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 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