ode45 2 degree of freedom
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponses (1)
darova
le 12 Sep 2019
Take a closer look on example from MATLAB help
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])
0 commentaires
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!