MATLAB Answers

How to fit one variable data into multiple ode equations

2 ビュー (過去 30 日間)
Hi there
I have one set of experimental data for y(1) but I have 4-set of ODE equations as follows:
dy1/dt = F1(y1,y2,y3,y4,par1, par2, par3, par4,t)
dy2/dt = F2(y1,y2,y3,y4,par1, par2, par3, par4,t)
dy3/dt = F3(y1,y2,y3,y4,par1, par2, par3, par4,t)
dy4/dt = D4(y1,y2,y3,y4,par1, par2, par3, par4,t)
I have only experimental data for y(1), I need to fit all four equations to best parameters to best fit to one available data y(1).
Can MATLAB do this?
Thanks

  0 件のコメント

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

採用された回答

Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato 2020 年 7 月 5 日
編集済み: Thiago Henrique Gomes Lobato 2020 年 7 月 5 日
What you mean by y(1)? That you have data only for the first variable y1? Your equations seem to be coupled, so if you optimize all the parameters for y1, the other yX will also have a reasonable result based on your data. What you can do then is to have all parameters as optimization variables and define a cost function equals to the difference between the integration and your experimental data. A general code for this problem would be something like this:
function cost = opt(x,yexperimental)
par1=x(1);
par2=x(2);
...
% Integrate system
[t,y] = ode45(@(t,y)YourOdeFunction(t,y,par1,par2,par3,par4),tspan,y0)
...
% Calculate error
cost = rms(y-yexperimental)
end
%% Run optimizer
...
f = @(x)opt(x,yexperimental);
[par,fval] = fminsearch(f,x0)

  3 件のコメント

Ahmad Sedaghat
Ahmad Sedaghat 2020 年 7 月 7 日
Thanks Thiago for useful tips. The size of y(4,:) but size of yexperimental(1,:). So the cost should have one array cost(1,:). I didn't get it how cost will be used in optimizer? i am not expert in Matlab programming.
Ahmad Sedaghat
Ahmad Sedaghat 2020 年 7 月 8 日
Thanks very much Thiago I managed to program as you suggested. The fminsearch returns some of these coefficients negative values (I need them all positive). Is there a way to control that?
Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato 2020 年 7 月 10 日
I'm glad it helped. There's some complicated and easy ways to control that. The easiest one, and also probably the best in this case, is to make sure your function use the absolute value of x, so, in the end, it will not matter if fminsearch finds a negative coefficient. As, for example:
function cost = opt(x,yexperimental)
x = abs(x); % x always positive in the function
...
[par,fval] = fminsearch(f,x0);
par = abs(par); % Since x always positive, negative values from fminsearch are irrelevant

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by