Clear Filters
Clear Filters

How to model 3 Degrees of Freedom at once

2 views (last 30 days)
Siddharth Jain
Siddharth Jain on 9 Nov 2022
Edited: Torsten on 9 Nov 2022
I have been unable to code the follwing equations in matlab-

Answers (1)

Torsten
Torsten on 9 Nov 2022
Edited: Torsten on 9 Nov 2022
Define a solution vector y = (y1,y2,y3,y4,y5,y6) with
y1 = y_a, y2 = y_a_dot, y3 = z_a, y4 = z_a_dot, y5 = Theta_a, y6 = Theta_a_dot
and write out the differential equations for these 6 variables.
E.g. for y1 and y2:
dy1/dt = y2
dy2/dt = (-F_y(t) - k_ay*y1 - c_ay*y2)/m_a
Then use ODE45 to solve.
  2 Comments
Torsten
Torsten on 9 Nov 2022
You use Fy, Fz and T_a as functions of t. Thus you must define them as such:
Fy = @(t) 1
Fz = @(t) 1
T_a = @(t) 178
instead of
Fy=1;
Fz=1;
T_a = 178;
Torsten
Torsten on 9 Nov 2022
Edited: Torsten on 9 Nov 2022
You defined 6 equations, not 4.
tspan = [0 1];
y0 = zeros(6,1);
[T,Y] = ode45(@reduced,tspan,y0);
plot(T,Y)
function yp = reduced(t,y)
m_a = 0.5;
c_ay=1;
c_az=1;
k_ay= 1;
k_az =1;
Fy=@(t)1;
Fz=@(t)1;
T_a = @(t)178;
I_a = 2000;
R_a=1;
yp = zeros(6,1);
yp(1) = y(2);
yp(2) = (-Fy(t) - k_ay*y(1) - c_ay*y(2))/m_a;
yp(3) = y(4);
yp(4) = (-Fz(t) - k_az*y(3) - c_az*y(4))/m_a;
yp(5) = y(6);
yp(6) = (-T_a(t) - Fy(t)*R_a)/I_a;
end

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!