ode45 2 degree of freedom

1 回表示 (過去 30 日間)
David Botha
David Botha 2019 年 9 月 12 日
回答済み: darova 2019 年 9 月 12 日
Hi all.
trying to solve a 2 degree of freedom system but not getting the expected output.
Am I making a fundemental error?
Thanks in advance!
syms k1 k2 m1 m2 x1(t) x2(t)
Eqs = [m1*diff(x1(t),2) == -x1(t)*(k1)-x1(t)*(k2)+k2*x2(t) , ...
m2*diff(x2(t),2) == k1*x1(t)-k2*(x2(t)) ]
SymSys = odeToVectorField(Eqs)
F = matlabFunction(SymSys)
F = @(t,Y,k1,k2,m1,m2) [Y(2);...
-(k2.*Y(1)-k1.*Y(3))./m2;...
Y(4);...
-(-k2.*Y(1)+k1.*Y(3)+k2.*Y(3))./m1];
k1=24;
k2=3;
m1=9;
m2=1;
tspan=[0 20];
Y0=[0 0 1 0];
[t,y] = ode45( @(t,Y) F(t,Y,k1,k2,m1,m2), tspan, Y0);
figure(1)
plot(t, y)
grid

回答 (1 件)

darova
darova 2019 年 9 月 12 日
Take a closer look on example from MATLAB help
211Untitled.png
I suggest you to comment these lines (or remove) since you are using odeToVectorField
% F = @(t,Y,k1,k2,m1,m2) [Y(2);...
% -(k2.*Y(1)-k1.*Y(3))./m2;...
% Y(4);...
% -(-k2.*Y(1)+k1.*Y(3)+k2.*Y(3))./m1];
Also define your constants BEFORE equations
Use something like that to define or add variables from your ode function
syms t Y
F = matlabFunction(SymSys,'vars',[t Y])

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by