onecyclevoltage = WLTP.VoltageV;
onecyclecurrent = WLTP.CurrentA;
onecycletime = WLTP.Time;
initial_guesses = [0.00116 , 0.00126 , 0.0043 , 59.982 , 0.0213 ,300.0103];
options = optimoptions(@fmincon, 'MaxIterations', 40000, 'MaxFunEvals', 40000);
[estimated_params, min_rmse,estimated_capacity,~] = fmincon(@(params) objective_function(params, onecyclecurrent, onecyclevoltage, onecycletime), initial_guesses, [], [], [], [], [], [],[],options);
Solver stopped prematurely.
fmincon stopped because it exceeded the function evaluation limit,
options.MaxFunctionEvaluations = 4.000000e+04.
disp('Estimated Parameters:');
disp(estimated_params);
0.0012 0.0012 0.0043 59.9820 0.0213 300.0103
disp(['Minimum RMSE: ', num2str(min_rmse)]);
[~, U2, Uoc, simulated_voltage] = simulate_thevenin_model(estimated_params, onecyclecurrent, onecycletime);
simulated_voltage(1) = Uoc(1);
plot(onecycletime, onecyclevoltage, 'b-', 'LineWidth', 2);
plot(onecycletime, simulated_voltage, 'r--', 'LineWidth', 2);
title('Measured vs Simulated Voltage');
legend('Measured', 'Simulated');
function error = objective_function(params, onecyclecurrent, onecyclevoltage, onecycletime)
[U1, U2, Uoc, sim_volt,capacity] = simulate_thevenin_model(params, onecyclecurrent, onecycletime);
error = sqrt(mean((onecyclevoltage - sim_volt).^2));
function [U1, U2, Uoc, sim_volt,capacity] = simulate_thevenin_model(params, onecyclecurrent, ~)
U1 = zeros(size(onecyclecurrent));
U2 = zeros(size(onecyclecurrent));
Uoc = zeros(size(onecyclecurrent)) ;
sim_volt = zeros(size(onecyclecurrent));
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);
capacity = capacity + abs(onecyclecurrent(k)) * dt ;