fmincon for Battery Parameter Estimation

2 Ansichten (letzte 30 Tage)
Gokul Gopakumar
Gokul Gopakumar am 21 Mär. 2024
Bearbeitet: Torsten am 21 Mär. 2024
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);
Solver stopped prematurely. fmincon stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 4.000000e+04.
% Display estimated parameters
disp('Estimated Parameters:');
Estimated Parameters:
disp(estimated_params);
0.0012 0.0012 0.0043 59.9820 0.0213 300.0103
disp(['Minimum RMSE: ', num2str(min_rmse)]);
Minimum RMSE: 0.028285
% 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
Torsten
Torsten am 21 Mär. 2024
Bearbeitet: Torsten am 21 Mär. 2024
One thing that is obvious is that (RCha - RDch) must be reduced to one parameter so that 5 instead of 6 parameters are left to estimate.
I don't see at the moment if the same can be done for R1 and R2 resp. Tau1 and Tau2.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

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!

Translated by