Solve equations of Motion using Matlab ODE45

조회 수: 21 (최근 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 CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by