Problem when solving ODEs with ode45
Afficher commentaires plus anciens
Good day,
I have the following code where I simultaneously solve three second-order differential equations defined in 'ode3'.
My problem is that in the second last line in 'ode3', the denominator is Y3(3). This is the variable 'r' and is in the direction of a spring and stretches as a mass swings around at its endpoint. When I run the script I get NaN in my Y3 matrix, which then leads me to believe I'm dividing by zero some time. What I don't understand is why would that value become zero?
Any help is appreciated!
m1 = 4; %kg
m2 = 6; %kg
L = 1.5; %m
k = 100; %N/m
g = 9.81; %m/s2
% --------------------------------------------------------------
% Force parameters
% --------------------------------------------------------------
Fo = 100; %N
tf = 1;
F = @(t) (t<=tf)*Fo*sin(2*pi*t/tf);
ic3 = [0, 0, 0, 0, L, 0];
ode3 = @(t, Y3) [Y3(4);
Y3(5);
Y3(6);
(F(t) - m2*k*(L-Y3(3))*sin(Y3(2)))/m1;
(-F(t)*cos(Y3(2)) + m2*k*(L-Y3(3))*sin(Y3(2))*cos(Y3(2)) - 2*m1*Y3(6)*Y3(5) - m1*g*sin(Y3(2)))/(m1*Y3(3));
(-F(t)*sin(Y3(2)) + m2*k*(L-Y3(3))*sin(Y3(2))^2 + m1*Y3(3)*Y3(5)^2 + m1*g*cos(Y3(2)) + m1*k*(L-Y3(3)))/m1];
[t3, Y3] = ode45(ode3, [0, 3], ic3);
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Ordinary Differential Equations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!