ODE system with 2 degrees of freedom

19 次查看(过去 30 天)
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

采纳的回答

James Tursa
James Tursa 2021-10-27
编辑:James Tursa 2021-10-27
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

更多回答(1 个)

David Goodmanson
David Goodmanson 2021-10-27
编辑:David Goodmanson 2021-10-28
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));

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by