Problen with optimization of two parameters, and with differential equations
1 view (last 30 days)
Show older comments
I made this program for a chemistry class, but for some reason it shows that the objective function enters optimal values but there really isn't a good similarity between the real data and the optimized data, I don't know if it's a problem of how I wrote the optimizer or because of the resolution of differentials
the data is:
0 0
60 0.28
120 0.36
180 0.42
240 0.44
300 0.445
360 0.47
420 0.5
clc
clear all
%Valores iniciales de parametros
par0 = [690,30 ];
data = load('acido.txt');
%Entrada de prueba de presion
fun_objetivo = @(par)FunObjetivo(par,data(:,:));
t = data(:,1);
xe= data(:,2);
%Argumentos de entrada
A =[]; b =[];
Aeq =[]; beq =[];
lb =[500 0]; ub =[1000 100];
IntCon =[]; nonlcon =[];
nvar =2;
%Nelder_Mead
options = optimset('MaxIter',5000,'MaxFunEvals',...
3000,'FunValCheck','off','Display','iter');
%We use here the Nelder-Mead method
par_optimos = fminsearchbnd(fun_objetivo,par0,lb,ub, options);
function FO =FunObjetivo(par,data)
%Vector tiempo
t = data(:,1);
%Vector conversion real
xe = data(:,2);
%Constantes
cc=0.365851537;
ca0=7.718472259;
keq=3.6021;
T=323.15;
k0=par(1);
Ea=par(2);
%Simulation
y0=0;
dxadt=@(t,xa) k0*exp(-Ea/(8310*T))*cc*ca0*((1-xa^2)-((xa^2)/keq));
tspan=[0:60:420];
[t,xa]=ode45(dxadt,tspan,y0);
%Valor de la Funcion Objetivo
FO = sum((xe-xa).^2);
end
0 Comments
Answers (2)
Torsten
on 17 Apr 2023
Edited: Torsten
on 17 Apr 2023
All curves that stem from your model tend to sqrt(keq/(1+keq)). Since your measurement data tend to 0.5, my guess is that you have to choose keq such that 0.5 = sqrt(keq/(1+keq)) to get a proper fit. The constant you try to fit gives the velocity with which this equilibrium value of 0.5 is reached.
syms c t keq xa(t)
eqn = diff(xa,t)==c*((1-xa^2)-xa^2/keq);
cond = xa(0)==0;
sol = dsolve(eqn,cond)
keqnum = double(solve(sqrt(keq/(keq+1))==0.5,keq))
%keqnum=3.6021;
sol = matlabFunction(subs(sol,keq,keqnum));
data=[0 0
60 0.28
120 0.36
180 0.42
240 0.44
300 0.445
360 0.47
420 0.5];
t = data(:,1);
xe = data(:,2);
c = 0:0.001:0.01;
hold on
plot(t,xe,'o')
for i = 1:numel(c)
xa = sol(c(i),t);
plot(t,xa)
end
hold off
0 Comments
See Also
Categories
Find more on Quadratic Programming and Cone Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!