Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

lsqcurvefit with ODE45

273 views
Skip to first unread message

Edward

unread,
Mar 19, 2011, 2:20:23 PM3/19/11
to
I am trying to curve fit of an ODE using lsqcurvefit.
These are the points that I am trying to fit:
t=[0 2 4 8 12 24];
A=[8.216 8.216 8.002 7.834 7.882 8.312];

My equation is:
alpha=1+B.*(1-exp(-C.*t.*tau));
dydt = Kg.*(1-y./ymax).*y-((C.^H).*Kk)./(C.^H+alpha.*C50k.^H).*y;

I am trying to estimate 6 parameters which are B, tau, ymax, H, C50k, and Kk with minimal sum of squares.
I have start a file, but I am receiving errors such as:
lsqcurvefit stopped because the size of the current step is less than
the default value of the step size tolerance.

my codes are:
%First File
function dydt = BP1(t,y,ModelParams)
C=4;
Kg=2.31;
Kk=ModelParams(1);
C50k=ModelParams(2);
H=ModelParams(3);
ymax=ModelParams(4);
B=ModelParams(5);
tau=ModelParams(6);
alpha=1+B*(1-exp(-C*t*tau));
dydt = Kg*(1-y/((ymax*10^9))*y-((C^H)*Kk)/(C^H+alpha*C50k^H))*y;

%Second File
function y = BP2(ModelParams,t,y0)
[t,y]=ode45(@BP1,t,y0,[],ModelParams);

%Third File
t=[0 2 4 8 12 24];
y0=8.216*10^8;
A=[8.216 8.216 8.002 7.834 7.882 8.312];
ydata=A'*10^8;
ydata(1)=y0;
ModelParams0=[3.2,2,2.4,10,6,.01];
options = optimset('MaxFunEvals', 1000, 'MaxIter', 1000);
ModelParams_Fit=lsqcurvefit(@BP2,ModelParams0,t,ydata,[],[],options,y0);
parameters = (ModelParams_Fit)

Would fmincon be more reliable for parameter estimation?

Edward

unread,
Mar 19, 2011, 2:21:04 PM3/19/11
to

Alan Weiss

unread,
Mar 21, 2011, 7:48:37 AM3/21/11
to
On 3/19/2011 2:20 PM, Edward wrote:
> I am trying to curve fit of an ODE using lsqcurvefit.
*snip*

> I have start a file, but I am receiving errors such as:
> lsqcurvefit stopped because the size of the current step is less than
> the default value of the step size tolerance.
*snip*

>
> Would fmincon be more reliable for parameter estimation?

The exit message you report does not represent an error. Instead, it
tells you the reason lsqcurvefit stopped. lsqcurvefit probably returned
a good solution. For more information, see
http://www.mathworks.com/help/toolbox/optim/ug/brwvb8m.html#brw34o7

Alan Weiss
MATLAB mathematical toolbox documentation

Marc

unread,
Jul 6, 2011, 12:12:07 AM7/6/11
to
Alan Weiss <awe...@mathworks.com> wrote in message <im7dul$g4n$1...@fred.mathworks.com>...

I am guessing that the major reason why some use nlinfit or lsqcurvefit depends on whether you have the stats or optimization toolbox. With lsqcurvefit, I would think that the LM algorithm would be better for most odes?

Not sure, but in your options you may want to try LM method vs the trust region which is the default for lsqcurvefit.

If you have the stats toolbox, I recommend trying nlinfit with some of the options. LM is default for nlinfit plus you can develop confidence and predictive intervals with nlinfit combined with nlparci and nlpredci.

0 new messages