fmincon for Battery Parameter Estimation
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello,
I am trying to build Thevenin Model for ym LFP Cell. I am attaching the programme. When you run the programme, graph with comparison of simulated and measured voltage will be displayed. But as you can see from the graph, it is not exactly correct. Can somebody help me regarding this.
load("WLTP.mat")
onecyclevoltage = WLTP.VoltageV;
onecyclecurrent = WLTP.CurrentA;
onecycletime = WLTP.Time;
dt =0.1;
% Define initial parameter guesses
initial_guesses = [0.00116 , 0.00126 , 0.0043 , 59.982 , 0.0213 ,300.0103]; % [RCha, RDch, R1, Tau1, R2, Tau2]
% Define optimization options
%options = optimoptions(@fmincon, 'Algorithm', 'active-set', 'MaxIterations', 18101, 'MaxFunEvals', 18101);
options = optimoptions(@fmincon, 'MaxIterations', 40000, 'MaxFunEvals', 40000);
% Define optimization options
%options = optimoptions(@ga, 'MaxGenerations', 1851958, 'PopulationSize', 50);
% Perform parameter estimation using fmincon
[estimated_params, min_rmse,estimated_capacity,~] = fmincon(@(params) objective_function(params, onecyclecurrent, onecyclevoltage, onecycletime), initial_guesses, [], [], [], [], [], [],[],options);
% Display estimated parameters
disp('Estimated Parameters:');
disp(estimated_params);
disp(['Minimum RMSE: ', num2str(min_rmse)]);
% Simulate the Thevenin model using the estimated parameters
[~, U2, Uoc, simulated_voltage] = simulate_thevenin_model(estimated_params, onecyclecurrent, onecycletime);
simulated_voltage(1) = Uoc(1);
% Plot the measured and simulated voltage
figure;
plot(onecycletime, onecyclevoltage, 'b-', 'LineWidth', 2);
hold on;
plot(onecycletime, simulated_voltage, 'r--', 'LineWidth', 2);
xlabel('Time (s)');
ylabel('Voltage (V)');
title('Measured vs Simulated Voltage');
legend('Measured', 'Simulated');
grid on;
hold off;
function error = objective_function(params, onecyclecurrent, onecyclevoltage, onecycletime)
% Simulate the Thevenin model with the given parameters
[U1, U2, Uoc, sim_volt,capacity] = simulate_thevenin_model(params, onecyclecurrent, onecycletime);
% Calculate the root mean square error (RMSE) between measured and simulated voltage
error = sqrt(mean((onecyclevoltage - sim_volt).^2));
end
function [U1, U2, Uoc, sim_volt,capacity] = simulate_thevenin_model(params, onecyclecurrent, ~)
% Extract parameters
RCha = params(1);
RDch = params(2);
R1 = params(3);
Tau1 = params(4);
R2 = params(5);
Tau2 = params(6);
% Initialize variables
U1 = zeros(size(onecyclecurrent));
U2 = zeros(size(onecyclecurrent));
Uoc = zeros(size(onecyclecurrent)) ;
Uoc(1) = 3.3398;
sim_volt = zeros(size(onecyclecurrent));
dt =0.1;
% Initialize capacity
capacity = 20;
% Simulation loop
for k = 2:length(onecyclecurrent)
U1(k) = U1(k - 1) * exp(-dt/ (Tau1)) + onecyclecurrent(k) * R1 * (1 - exp(-dt/ Tau1));
U2(k) = U2(k - 1) * exp(-dt / Tau2) + onecyclecurrent(k) * R2 * (1 - exp(-dt / Tau2));
Uoc(k) = Uoc(k - 1) + onecyclecurrent(k) * (RCha - RDch);
sim_volt(k) = Uoc(k) + U1(k) + U2(k);
% Accumulate charge/discharge to estimate capacity
capacity = capacity + abs(onecyclecurrent(k)) * dt ; % Convert current from A to Ah
end
end
1 Kommentar
Antworten (0)
Siehe auch
Kategorien
Mehr zu Optimization Toolbox finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!