Parameter estimation with fminsearch and ODE23s

1 Ansicht (letzte 30 Tage)
Carla White
Carla White am 10 Apr. 2019
Beantwortet: Matt J am 10 Apr. 2019
Hi all,
I am trying to write a code to estimate two parameters in a small system of ODEs. The ODEs are
and the output function is , with a and b the parameters to be estimated. The code I have so far is
x0=[0.0510e-9;0.1190e-9];
t1=linspace(0,50,21);
data=1e-9*[0.2376,0.2345,0.2316,0.2238,0.2141,0.2110,0.2140,0.2054,0.2003,0.2006,0.1881...
0.1917,0.1833,0.1814,0.1768,0.1664,0.1725,0.1623,0.1545,0.1513,0.1581];
p0=[1e3;1e-6];
opts = optimset('TolX',1e-15,'MaxFunEvals',5000,'TolFun',1e-15);
[B,l] = fminsearch(@(p) fit_data_diss(p,t1,x0,data), p0, opts)
B(1)
B(2)
p=[B(1),B(2)];
[t2,y2]= ode23s(@(t,y)dissociation(t,y,p),t1,x0);
Approx=-2*y2(:,1)-y2(:,2)+2*p(2);
figure
hold on
plot(t1,data,'*')
plot(t2,Approx)
function err = fit_data_diss(p,t,x0,dat)
[t,ys]=ode23s(@(t,y)dissociation(t,y,p),t,x0);
yr = -2*ys(:,1)-ys(:,2)+2*p(2);
err = norm(dat-yr);
end
function dydt = dissociation(t,y,p)
dydt = zeros(2,1);
dydt(1)=p(1)*y(2);
dydt(2)=p(1)*(p(2)-y(1)-2*y(2));
end
However, when I use the estimated parameters to plot the function it is nowhere near to the data. I have tried reducing the stopping tolerances but that makes no difference. Can anyone please point out what I am doing wrong? Thanks, Carla.

Antworten (1)

Matt J
Matt J am 10 Apr. 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by