ODE system with 2 degrees of freedom

19 Ansichten (letzte 30 Tage)
Nader Mohamed
Nader Mohamed am 27 Okt. 2021
Kommentiert: Nader Mohamed am 28 Okt. 2021
I'm trying to write this system of odes and then solve it with ode45, but I'm having trouble writing the function for the system:
k,J1,J2 and b are known. I tried to write this code but it doesnt work:
function dydt = ODEsystem(t,y)
k = 100;
b = 10;
J1 = 0.2;
J2 = 0.1;
dydt = zeros(6,1);
dydt(1) = y(2);
dydt(2) = y(3);
dydt(3) = k/J1 * dydt(1) - k/J1 * dydt(4);
dydt(4) = y(5);
dydt(5) = y(6);
dydt(6) = b/J2 * dydt(5) + k/J2 * dydt(4) - k/J2 * dydt(1);
end

Akzeptierte Antwort

James Tursa
James Tursa am 27 Okt. 2021
Bearbeitet: James Tursa am 27 Okt. 2021
I only see two variables, θ1 and θ2, and each is part of a 2nd order equation. So that would mean a 2 x 2 = 4 element state vector, not 6 element state vector as you are using. E.g., I would have the states defined as
y(1) =
y(2) =
y(3) =
y(4) =
which would mean the derivative function would be:
function dydt = ODEsystem(t,y)
k = 100;
b = 10;
J1 = 0.2;
J2 = 0.1;
theta1ddot = k/J1 * y(1) - k/J1 * y(2);
theta2ddot = b/J2 * y(4) + k/J2 * y(2) - k/J2 * y(1);
dydt = [y(3);y(4);theta1ddot;theta2ddot];
end

Weitere Antworten (1)

David Goodmanson
David Goodmanson am 27 Okt. 2021
Bearbeitet: David Goodmanson am 28 Okt. 2021
Hi Nader,
you only need four variables, theta1, theta1dot, theta2, theta2dot (not six). Try
function dydt = ODEsystem(t,y)
k = 100;
b = 10;
J1 = 0.2;
J2 = 0.1;
% y = [theta1; theta1dot; theta2; theta2dot]
dydt = zeros(4,1);
dydt(1) = y(2);
dydt(3) = y(4);
dydt(2) = (k/J1)*(y(1)-y(3));
dydt(4) = (b/J2)*y(4) +(k/J2)*(y(3)-y(1));

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by