Parameter fitting using nlinfit (high order ODEs)

I am trying to fit data on multi-dimensional ODEs:
function output = myfunc(pars,tspan)
% we just rename the variable here for use in the ODE
k = pars;
function dCadt = ode(t,Ca)
% this is the ODE we are fitting to
dCadt(1) = -k(1)*Ca(1);
dCadt(2) = k(2)*Ca(1)*Ca(2);
end
% Initial concs. of Ca.
Cao = [2 3]';
[t,Ca] = ode15s(@ode,tspan,Cao);
output = Ca;
end % myfunc
Calling function:
tspan = [0 0.1 0.2 0.4 0.8 1]';
Cadata = [2.0081 1.5512 1.1903 0.7160 0.2562 0.1495;
2.0081 1.5512 1.1903 0.7160 0.2562 0.1495]';
parguess = [1.3 2]; % nonlinear fits need initial guesses
[pars, resid, J] = nlinfit(tspan,Cadata,@myfunc,parguess)
However it always give this error:
Error using nlinfit (line 185)
Requires a vector second input argument.
When I run same program with lsqcurvefit, it runs smoothly!
Please anyone help me to sort this error!

回答 (1 件)

Star Strider
Star Strider 2014 年 9 月 5 日

0 投票

That has to do with differences between lsqcurvefit (that will fit matrix dependent variables) and nlinfit that will only fit vector dependent variables.

4 件のコメント

Learner
Learner 2014 年 9 月 5 日
Thanks for the clarification.
Star Strider
Star Strider 2014 年 9 月 5 日
My pleasure!
Learner
Learner 2014 年 9 月 6 日
Is it possible to use 'nlparci' with lsqcurvefit?
Or do you know any other command similar to nlparci which can be used with lsqcurvefit?
Thanks in advance.
Star Strider
Star Strider 2014 年 9 月 6 日
I don’t remember if nlparci will work when you’re fitting two dependent variables, since it’s been a while since I tried that. I believe it will, but I know nlpredci will not.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeSystems of Nonlinear Equations についてさらに検索

タグ

質問済み:

2014 年 9 月 5 日

コメント済み:

2014 年 9 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by