Problen with optimization of two parameters, and with differential equations
    조회 수: 2 (최근 30일)
  
       이전 댓글 표시
    
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
답변 (2개)
  Torsten
      
      
 2023년 4월 17일
        
      편집: Torsten
      
      
 2023년 4월 17일
  
      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
참고 항목
카테고리
				Help Center 및 File Exchange에서 Systems of Nonlinear Equations에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

