MATLAB code to find unknown parameters in ODEs using LM method

3 次查看(过去 30 天)
Hello, I am trying to write a code for solving system of linear ODE with unknown parameters that need to fit the experimental data. I tried doing it by using this:
But it didn't work. Or maybe I didn't do it properly because I didn't really understand what was what and how the variables were defined. My problem is:
[M]x_double_dot + [C]x_dot + [K]x = {0};
The experimental data is called "exp_open". I won't show exp_open here because it contains 15001 samples. I don't know if i did a mistake when writing the system in a state space form in order to use ode45.
But i obtain an error that said y and exp_open has not the same dimension.
Thank u for your help.
Here is my code :
km11=5.44e+5;
km15=-4.85e+7;
km55=-2073095808.81460221;
km51=-4.85e+7;
km0(1)=km11;
km0(2)=km15;
km0(3)=km55;
km0(4)=km51;
km_estimate=lsqnonlin(@(km)odefit_lm(t,exp_open,km),km0);
function [ err ] = odefit_lm( t,exp_open,km )
time=0:0.1:1500;
km11=km(1);
km15=km(2);
km55=km(3);
km51=km(4);
y0=[0;pi/18;0;0;0;0];
[t,y]=ode45(@(t,y)f_lm(t,y,km11,km15,km55,km51),time,y0);
err=y-exp_open;
end
function [dydt] = f_lm( t,y,km11,km15,km55,km51 )
M(1,1)=8.3163e+7;
M(1,2)=-2.6982e+9;
M(1,3)=1.8107e+6;
M(2,2)=5.6542e+11;
M(2,3)=3.4131e+8;
M(3,3)=1.4249e+6;
M(2,1)=M(1,2);
M(3,1)=M(1,3);
M(3,2)=M(2,3);
K(1,1)=km11;
K(1,2)=km15;
K(1,3)=0;
K(2,1)=km51;
K(2,2)=1.4604e+10+km55;
K(2,3)=0;
K(3,1)=0;
K(3,2)=0;
K(3,3)=1.4249e+6;
C(1,1)=1.8448e+5;
C(2,2)=1.8286e+10;
C(3,3)=4.0008e+10;
C(1,2)=5.8081e+7;
C(1,3)=-8.5911e+7;
C(2,3)=-2.7048e+10;
C(2,1)=C(1,2);
C(3,1)=C(1,3);
C(3,2)=C(2,3);
dydt(1)= y(4);
dydt(2)=y(5);
dydt(3)=y(6);
dydt(4:6)=-(M^(-1))*K*y(1:3)-(M^(-1))*C*y(4:6);
dydt=dydt';
end
In fact, i made some modifications to the code and i obtained another error:
Attempted to access y(5); index out of bounds because numel(y)=4.
Error in f_lm (line 49)
dydt(2)=y(5);
Error in odefit_lm>@(t,y)f_lm(t,y,km) (line 3)
[t,y]=ode45(@(t,y)f_lm(t,y,km),time,[5.44e+5 -4.85e+7 -2073095808.81460221 -4.85e+7]);
Error in odearguments (line 87)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 113)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in odefit_lm (line 3)
[t,y]=ode45(@(t,y)f_lm(t,y,km),time,[5.44e+5 -4.85e+7 -2073095808.81460221 -4.85e+7]);
Error in @(km)odefit_lm(time,exp_y,km)
Error in lsqnonlin (line 194)
initVals.F = feval(funfcn{3},xCurrent,varargin{:});
Error in test_lm (line 45023)
km_estimate=lsqnonlin(@(km)odefit_lm(time,exp_y,km),km0);
Caused by:
Failure in initial user-supplied objective function evaluation. LSQNONLIN cannot continue.
  1 个评论
Jan
Jan 2022-10-14
Please post a copy of the complete error message. The details matter and it is not efficient to guess them.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by