Solve equations of Motion using Matlab ODE45

62 ビュー (過去 30 日間)
Brian Peoples
Brian Peoples 2020 年 4 月 9 日
コメント済み: James Tursa 2020 年 4 月 9 日
Solve the following set of equations of motion using Matlab ODE45:
(m +m )x+m Lcos−m L2 sin+kx=01222
L + x cos + g sin = 0
Assume
m1=1 kg, m2=2 kg, L=1 m, k=1 N/m, g=10 m/s2.
Consider the following initial conditions:
x(0)=1x(0)=0(0)=1(0)=0
To enter this set of equations into your Matlab code, you need to re-write them in the first order form. That will give you 4 equations, and you will have to enter those equations into your ODE solver. You will have y(1), y(2), y(3) and y(4) as your unknowns.
Basically all we've done to solve 2nd order differential equations thus far was use a script and function only solving for one ode at a time w two initial conditions. Here would be my code for an older assignment:
script
R = 1;
g = 10; %coefficients
phi = 30;
tspan = [0 10]; % Time
initial_cond = [0,0]; %initial conditions
[t,y] = ode45(@(t,y)ODE_funct_second_order(t, y, R, g, phi),tspan,initial_cond);
theta = y(:,1);
L = -R.*y(:,1);
function
function dydt = ODE_fnct_second_order(t, y, L, g)
dydt = [y(2); -(3/2)*g*sin(y(1))/L];
end

採用された回答

James Tursa
James Tursa 2020 年 4 月 9 日
編集済み: James Tursa 2020 年 4 月 9 日
You will have a 4-element state vector instead of 2.
initial_cond = [1;1;0;0];
[t,y] = ode45(@(t,y)ODE_funct_fourth_order(t, y, m1, m2, L, k, g),tspan,initial_cond);
with
function dydt = ODE_funct_fourth_order(t, y, m1, m2, L, k, g)
dydt = [y(3);y(4);something;something];
end
where y is
y(1) = x
y(2) = theta
y(3) = xdot
y(4) = thetadot
You get the expressions for dydt(3) and dydt(4) by solving (e.g. on paper or inside your derivative function using backslash \ operator) your matrix equations for xdotdot and thetadotdot.
  2 件のコメント
Brian Peoples
Brian Peoples 2020 年 4 月 9 日
in the function where you write dydt = [y(3);y(4);something;something];
can you further explain that?
James Tursa
James Tursa 2020 年 4 月 9 日
The "something,something" is for you to fill in. You solve the matrix differential equations for xdotdot and thetadotdot, and those expressions go into the "something,something"

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by