Optimizing parameters in ODE

5 ビュー (過去 30 日間)
Bibek Dhami
Bibek Dhami 2019 年 9 月 18 日
コメント済み: Star Strider 2019 年 9 月 24 日
Hi I have a set of experimental data. I want to fit this experimental data to first order differential equation of the form dy/dt = -a*n-b*n^2-c*n^3 to optimize the value of constants a,b and c. Can anyone help in this regards? I am new to matlab as this question might be too simple for others. Thanks in advance.

採用された回答

Star Strider
Star Strider 2019 年 9 月 18 日
This is a simple, separable differential equation that you can likely solve by hand.
Using the Symbolic Math Toolbox:
syms a b c n y(t) y0
DEqn = diff(y) == -a*n-b*n^2-c*n^3;
Eqn = dsolve(DEqn, y(0)==y0)
fcn = matlabFunction(Eqn, 'Vars',{[a,b,c],t,n,y0})
produces:
Eqn =
y0 - t*(c*n^3 + b*n^2 + a*n)
fcn =
function_handle with value:
@(in1,t,n,y0) y0-t.*(in1(:,1).*n+in1(:,2).*n.^2+in1(:,3).*n.^3)
or more conveniently:
fcn = @(in1,t,n,y0) y0-t.*(in1(:,1).*n+in1(:,2).*n.^2+in1(:,3).*n.^3);
with ‘in1’ corresponding to [a,b,c] in that order. Supply values for ‘n’ and ‘y0’, then present it to the nonlinear parameter estimation function of your choice as:
objfcn = @(in1,t) fcn(in1,t,n,y0)
Or, since it is ‘linear in the parameters’ you can re-write it as a design matrix and use linear methods such as mldivide,\ to solve it as well.
  4 件のコメント
Bibek Dhami
Bibek Dhami 2019 年 9 月 24 日
Thank you Star Strider for your code. It helped me a lot though I am stuck in the initial condition of parameters to exactly fit it.
Star Strider
Star Strider 2019 年 9 月 24 日
As always, my pleasure!
My code estimates the initial condition as well, estimating it as ‘b(4)’, in the printed results as ‘ic’. So an initial estimate for it shoulld be ‘B0(4)’.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by