Solve equations of Motion using Matlab ODE45
62 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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 个评论
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 Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!