Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
lsqcurvefit with ODE45

Subject: lsqcurvefit with ODE45

From: Edward

Date: 19 Mar, 2011 18:20:23

Message: 1 of 3

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?

Subject: lsqcurvefit with ODE45

From: Alan Weiss

Date: 21 Mar, 2011 11:48:37

Message: 2 of 3

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

Subject: lsqcurvefit with ODE45

From: Marc

Date: 6 Jul, 2011 04:12:07

Message: 3 of 3

Alan Weiss <aweiss@mathworks.com> wrote in message <im7dul$g4n$1@fred.mathworks.com>...
> 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

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.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us