![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/811454/image.png)
Using ode45 for a non linear differential equation with a term in a vector form
1 回表示 (過去 30 日間)
古いコメントを表示
Maxime Jean Marc Lenoir
2021 年 11 月 23 日
コメント済み: Star Strider
2021 年 11 月 24 日
Hello,
I want to solve the 2nd order differential equation:
d^2(xus)/dt^2 = -K/Mus*xus-Ms/Mus*d^2(xs)/dt^2
I found as = d^2(xs)/dt^2 experimentally with potentiometer so I have as a 90000x1 vector that corresponds to the acceleration at each time t and now I want to find xus in function of this same time t using ode45
The problem is that I don't know how to deal with as in ode45 and I have the error:
Unable to perform assignment because the size of the left side is 1-by-1 and the size
of the right side is 0-by-1.
Considering that as is given the rest of my code is:
Mus=100;
Ms=10;
K=1000;
tspan=linspace(0,(size(as)-1)*0.02,size(as));
x0 = [0 0];
[t,x] = ode45(@(t,x) fun(t,x,as,Mus,Ms,K,tspan), tspan, x0);
function dx_dt = fun(t,x,as,Mus,Ms,K,tspan)
i=find(tspan==t);
a=as(i);
dx_dt(1,1) = x(2);
dx_dt(2,1) =-K/Mus*x(1)-Ms/Mus*a;
end
Thank you in advance for your help
0 件のコメント
採用された回答
Star Strider
2021 年 11 月 24 日
I do not understand the problem.
Is the objective to estimate a parameters of the differential equation from data?
The time value at each iteration is supplied to the ode45 function so there is no reason to specify it directly. If the data were collected at specific times, use that time vector for ‘tspan’ in the differential equation call. Are the values of ‘K’, ‘Ms’, and ‘Mus’ known, or are they to be estimated (as parameters) from the data?
The derivation is fairly straightforward using the Symbolic Math Toolbox —
syms D2xs K Ms Mus T t xus(t) Y
Dxus = diff(xus);
D2xus = diff(Dxus);
Eqn = D2xus == -K/Mus*xus-Ms/Mus*D2xs
[VF,Sbs] = odeToVectorField(Eqn)
xusfcn = matlabFunction(VF, 'Vars',{T,Y,D2xs,K,Ms,Mus})
It would help to upload/attach the time and
vectors (as a matrix as (90000x2) matrix if the intent is to estimate parameters from it.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/811454/image.png)
.
6 件のコメント
Star Strider
2021 年 11 月 24 日
As always, my pleasure!
The order of the arguments can be changed by using the 'Vars' name-value pair in the matlabFunction call. That might make them easier to work with. (All calls to the function have to have their argument list changed to match it, if it the order is changed.)
.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!