# Does this represent a 3DOF system if not how can I incorporate it as such?

조회 수: 4(최근 30일)
Keenan 2022년 7월 27일
답변: Sam Chak 2022년 7월 28일
I am trying to simulate a 3DOF dynamic model of a spaceplane for a project with 2 element control thrust and angle of attack, and the code attached is what ive been using to simulate different output scenarios. Does the system represent that of a 3DOF system or have I only managed to achieve a 2DOF system with 2 element control. Any help is appreciated.
See code below;
% Based on X-34 launch specs and parameters
% Variable List:
% Delta = Time step (s)
% t = Time (s)
% Thrust = Thrust (N)
% Mass = Mass (kg)
% Mass_Rocket_With_Fuel = Mass with fuel (kg)
% Mass_Rocket_Without_Fuel = Mass without fuel (kg)
% Theta = Angle (deg)
% C = Drag coefficient
% Rho = Air density (kg/m^3)
% A = Frontal Rocket projected area (m^2)
% Gravity = Gravity (m/s^2)
% n = Counter
% Fn = Normal force (N)
% Drag = Drag force (N)
% Fx = Sum of forces in the horizontal direction (N)
% Fy = Sum of forces in the vertical direction (N)
% Vx = Velocity in the horizontal direction (m/s)
% Vy = Velocity in the vertical direction (m/s)
% Vsum = Velocity components squared and multiplied
% Vm = Velocit Magnitude from sqrt(Vsum)
% Ax = Acceleration in the horizontal direction (m/s^2)
% Ay = Acceleration in the vertical direction (m/s^2)
% x = Horizontal position (m)
% y = Vertical position (m)
% Distance_x = Horizontal distance travelled (m)
% Distance_y = Vertical travelled (m)
% Distance = Total distance travelled (m)
% Memory_Allocation = Maximum number of time steps expected
% Parameters
Delta = 1; % Time step
Memory_Allocation = 30000; % Maximum number of time steps expected
% Preallocate memory for arrays
t = zeros(1, Memory_Allocation);
Thrust = zeros(1, Memory_Allocation);
Mass = zeros(1, Memory_Allocation);
Theta = zeros(1, Memory_Allocation);
Fn = zeros(1, Memory_Allocation);
Drag = zeros(1, Memory_Allocation);
Fx = zeros(1, Memory_Allocation);
Fy = zeros(1, Memory_Allocation);
Ax = zeros(1, Memory_Allocation);
Ay = zeros(1, Memory_Allocation);
Vx = zeros(1, Memory_Allocation);
Vy = zeros(1, Memory_Allocation);
x = zeros(1, Memory_Allocation);
y = zeros(1, Memory_Allocation);
Distance_x = zeros(1, Memory_Allocation);
Distance_y = zeros(1, Memory_Allocation);
Distance = zeros(1, Memory_Allocation);
C = 0.04; % Drag coefficient
Rho = 1.225; % Air density (kg/m^3)
A = 24.3916; % Frontal X-34 projected area (m^2)
Gravity = 9.81; % Gravity (m/s^2)
Mass_Rocket_With_Fuel = 13607.771; % Mass with Fuel (kg)
Mass_Rocket_Without_Fuel = 8164.6627; % Mass without Fuel (kg)
Theta(1) = 70; % Initial angle (deg)
Vx(1) = 0; % Initial horizontal speed (m/s)
Vy(1) = 0; % Initial vertical speed (m/s)
x(1) = 0; % Initial horizontal position (m)
y(1) = 0.1; % Initial vertical position (m)
Distance_x(1) = 0; % Initial horizontal distance travelled (m)
Distance_y(1) = 0; % Initial vertical distance travelled (m)
Distance(1) = 0; % Initial distance travelled (m)
Mass(1) = Mass_Rocket_With_Fuel; % Initial rocket mass (kg)
n = 1; % Initial time step
while y(n) > 0 % Run until rocket hits the ground
n = n+1; % Increment time step
t(n)= (n-1)*Delta; % Elapsed time
% Determine rocket thrust and mass based on launch phase assumption of
% 150s burn time
if t(n) <= 1 % Launch phase 1
Thrust(n) = 266893*t(n);
Mass(n) = Mass_Rocket_With_Fuel;
elseif t(n) > 1 && t(n) < 150 % Launch phase 2
Thrust(n) = 266893;
Mass(n) = Mass_Rocket_With_Fuel;
elseif t(n) >= 150 % Launch phase 3
Thrust(n) = 0;
Mass(n) = Mass_Rocket_Without_Fuel; % Rocket burned all fuel
end
% Normal force calculations
Fn(n) = Mass_Rocket_With_Fuel*Gravity*cosd(Theta(1));
% Drag force calculation
Drag(n)= 0.5*C*Rho*A*(Vx(n-1)^2+Vy(n-1)^2); % Calculate drag force
% Sum of forces calculations
Fx(n)= Thrust(n)*cosd(Theta(n-1))-Drag(n)*cosd(Theta(n-1))...
-Fn(n)*sind(Theta(n-1)); % Sum x forces
Fy(n)= Thrust(n)*sind(Theta(n-1))-(Mass(n)*Gravity)-...
Drag(n)*sind(Theta(n-1))+Fn(n)*cosd(Theta(n-1)); % Sum y forces
% Acceleration calculations
Ax(n)= Fx(n)/Mass(n); % Net accel in x direction
Ay(n)= Fy(n)/Mass(n); % Net accel in y direction
% Velocity calculations
Vx(n)= Vx(n-1)+Ax(n)*Delta; % Velocity in x direction
Vy(n)= Vy(n-1)+Ay(n)*Delta; % Velocity in y direction
Vsum(n)= Vx(n-1)^2+Vy(n-1)^2*Delta;
Vm(n)= sqrt(Vsum(n)); %Velocity Magnitude
% Position calculations
x(n)= x(n-1)+Vx(n)*Delta; % Position in x direction
y(n)= y(n-1)+Vy(n)*Delta; % Position in y direction
% Distance calculations
Distance_x(n) = Distance_x(n-1)+abs(Vx(n)*Delta); % Distance in x
Distance_y(n) = Distance_y(n-1)+abs(Vy(n)*Delta); % Distance in y
Distance(n) = (Distance_x(n)^2+Distance_y(n)^2)^(1/2); % Total distance
% Rocket angle calculation
Theta(n)= atand(Vy(n)/Vx(n)); % Angle defined by velocity vector
end
% Figure 1
subplot(5,2,10)
plot(x(1:n),y(1:n));
xlabel({'Range (m)'});
ylabel({'Altitude (m)'});
title({'Trajectory'});
% Figure 2
subplot(5,2,9)
plot(t(1:n),Vx(1:n));
xlabel({'Time (s)'});
ylabel({'Vx (m/s)'});
title({'Vertical Velocity'});
% Figure 3
subplot(5,2,8)
plot(t(1:n),Vy(1:n));
xlabel({'Time (s)'});
ylabel({'Vy (m/s)'});
title({'Horizontal Velocity'});
% Figure 4
subplot(5,2,7)
plot(t(1:n),Theta(1:n));
xlabel({'Time (s)'});
ylabel({'Theta (Deg)'});
title({'Theta'});
% Figure 5
subplot(5,2,6)
plot(Distance(1:n),Theta(1:n));
xlabel({'Distance (m)'});
ylabel({'Theta (Deg)'});
title({'Theta at Launch'});
% Figure 6
subplot(5,2,5)
plot(t(1:n),Mass(1:n));
xlabel({'Time (s)'});
ylabel({'Mass (kg)'});
title({'Rocket Mass'});
% Figure 7
subplot(5,2,4)
plot(t(1:n),Thrust(1:n));
xlabel({'Time (s)'});
ylabel({'Thrust (N)'});
title({'Thrust'});
% Figure 8
subplot(5,2,3)
plot(t(1:n),Drag(1:n));
xlabel({'Time (s)'});
ylabel({'Drag (N)'});
title({'Drag Force'});
% Figure 9
subplot(5,2,2)
plot(Distance(1:n),Fn(1:n));
xlabel({'Distance (m)'});
ylabel({'Normal Force (N)'});
title({'Normal Force'});
% Figure 10
subplot(5,2,1)
plot(t(1:n),Vm(1:n));
xlabel({'Time (s)'});
ylabel({'Vm(n) (m/s)'});
title({'Velocity Magnitude'});

댓글을 달려면 로그인하십시오.

### 답변(1개)

Sam Chak 2022년 7월 28일
@Keenan, Looks like no error.
% Based on X-34 launch specs and parameters
% Variable List:
% Delta = Time step (s)
% t = Time (s)
% Thrust = Thrust (N)
% Mass = Mass (kg)
% Mass_Rocket_With_Fuel = Mass with fuel (kg)
% Mass_Rocket_Without_Fuel = Mass without fuel (kg)
% Theta = Angle (deg)
% C = Drag coefficient
% Rho = Air density (kg/m^3)
% A = Frontal Rocket projected area (m^2)
% Gravity = Gravity (m/s^2)
% n = Counter
% Fn = Normal force (N)
% Drag = Drag force (N)
% Fx = Sum of forces in the horizontal direction (N)
% Fy = Sum of forces in the vertical direction (N)
% Vx = Velocity in the horizontal direction (m/s)
% Vy = Velocity in the vertical direction (m/s)
% Vsum = Velocity components squared and multiplied
% Vm = Velocit Magnitude from sqrt(Vsum)
% Ax = Acceleration in the horizontal direction (m/s^2)
% Ay = Acceleration in the vertical direction (m/s^2)
% x = Horizontal position (m)
% y = Vertical position (m)
% Distance_x = Horizontal distance travelled (m)
% Distance_y = Vertical travelled (m)
% Distance = Total distance travelled (m)
% Memory_Allocation = Maximum number of time steps expected
% Parameters
Delta = 1; % Time step
Memory_Allocation = 30000; % Maximum number of time steps expected
% Preallocate memory for arrays
t = zeros(1, Memory_Allocation);
Thrust = zeros(1, Memory_Allocation);
Mass = zeros(1, Memory_Allocation);
Theta = zeros(1, Memory_Allocation);
Fn = zeros(1, Memory_Allocation);
Drag = zeros(1, Memory_Allocation);
Fx = zeros(1, Memory_Allocation);
Fy = zeros(1, Memory_Allocation);
Ax = zeros(1, Memory_Allocation);
Ay = zeros(1, Memory_Allocation);
Vx = zeros(1, Memory_Allocation);
Vy = zeros(1, Memory_Allocation);
x = zeros(1, Memory_Allocation);
y = zeros(1, Memory_Allocation);
Distance_x = zeros(1, Memory_Allocation);
Distance_y = zeros(1, Memory_Allocation);
Distance = zeros(1, Memory_Allocation);
C = 0.04; % Drag coefficient
Rho = 1.225; % Air density (kg/m^3)
A = 24.3916; % Frontal X-34 projected area (m^2)
Gravity = 9.81; % Gravity (m/s^2)
Mass_Rocket_With_Fuel = 13607.771; % Mass with Fuel (kg)
Mass_Rocket_Without_Fuel = 8164.6627; % Mass without Fuel (kg)
Theta(1) = 70; % Initial angle (deg)
Vx(1) = 0; % Initial horizontal speed (m/s)
Vy(1) = 0; % Initial vertical speed (m/s)
x(1) = 0; % Initial horizontal position (m)
y(1) = 0.1; % Initial vertical position (m)
Distance_x(1) = 0; % Initial horizontal distance travelled (m)
Distance_y(1) = 0; % Initial vertical distance travelled (m)
Distance(1) = 0; % Initial distance travelled (m)
Mass(1) = Mass_Rocket_With_Fuel; % Initial rocket mass (kg)
n = 1; % Initial time step
while y(n) > 0 % Run until rocket hits the ground
n = n+1; % Increment time step
t(n)= (n-1)*Delta; % Elapsed time
% Determine rocket thrust and mass based on launch phase assumption of
% 150s burn time
if t(n) <= 1 % Launch phase 1
Thrust(n) = 266893*t(n);
Mass(n) = Mass_Rocket_With_Fuel;
elseif t(n) > 1 && t(n) < 150 % Launch phase 2
Thrust(n) = 266893;
Mass(n) = Mass_Rocket_With_Fuel;
elseif t(n) >= 150 % Launch phase 3
Thrust(n) = 0;
Mass(n) = Mass_Rocket_Without_Fuel; % Rocket burned all fuel
end
% Normal force calculations
Fn(n) = Mass_Rocket_With_Fuel*Gravity*cosd(Theta(1));
% Drag force calculation
Drag(n)= 0.5*C*Rho*A*(Vx(n-1)^2+Vy(n-1)^2); % Calculate drag force
% Sum of forces calculations
Fx(n)= Thrust(n)*cosd(Theta(n-1))-Drag(n)*cosd(Theta(n-1))...
-Fn(n)*sind(Theta(n-1)); % Sum x forces
Fy(n)= Thrust(n)*sind(Theta(n-1))-(Mass(n)*Gravity)-...
Drag(n)*sind(Theta(n-1))+Fn(n)*cosd(Theta(n-1)); % Sum y forces
% Acceleration calculations
Ax(n)= Fx(n)/Mass(n); % Net accel in x direction
Ay(n)= Fy(n)/Mass(n); % Net accel in y direction
% Velocity calculations
Vx(n)= Vx(n-1)+Ax(n)*Delta; % Velocity in x direction
Vy(n)= Vy(n-1)+Ay(n)*Delta; % Velocity in y direction
Vsum(n)= Vx(n-1)^2+Vy(n-1)^2*Delta;
Vm(n)= sqrt(Vsum(n)); %Velocity Magnitude
% Position calculations
x(n)= x(n-1)+Vx(n)*Delta; % Position in x direction
y(n)= y(n-1)+Vy(n)*Delta; % Position in y direction
% Distance calculations
Distance_x(n) = Distance_x(n-1)+abs(Vx(n)*Delta); % Distance in x
Distance_y(n) = Distance_y(n-1)+abs(Vy(n)*Delta); % Distance in y
Distance(n) = (Distance_x(n)^2+Distance_y(n)^2)^(1/2); % Total distance
% Rocket angle calculation
Theta(n)= atand(Vy(n)/Vx(n)); % Angle defined by velocity vector
end
% Figure 1
subplot(5,2,10)
plot(x(1:n),y(1:n));
xlabel({'Range (m)'});
ylabel({'Altitude (m)'});
title({'Trajectory'});
% Figure 2
subplot(5,2,9)
plot(t(1:n),Vx(1:n));
xlabel({'Time (s)'});
ylabel({'Vx (m/s)'});
title({'Vertical Velocity'});
% Figure 3
subplot(5,2,8)
plot(t(1:n),Vy(1:n));
xlabel({'Time (s)'});
ylabel({'Vy (m/s)'});
title({'Horizontal Velocity'});
% Figure 4
subplot(5,2,7)
plot(t(1:n),Theta(1:n));
xlabel({'Time (s)'});
ylabel({'Theta (Deg)'});
title({'Theta'});
% Figure 5
subplot(5,2,6)
plot(Distance(1:n),Theta(1:n));
xlabel({'Distance (m)'});
ylabel({'Theta (Deg)'});
title({'Theta at Launch'});
% Figure 6
subplot(5,2,5)
plot(t(1:n),Mass(1:n));
xlabel({'Time (s)'});
ylabel({'Mass (kg)'});
title({'Rocket Mass'});
% Figure 7
subplot(5,2,4)
plot(t(1:n),Thrust(1:n));
xlabel({'Time (s)'});
ylabel({'Thrust (N)'});
title({'Thrust'});
% Figure 8
subplot(5,2,3)
plot(t(1:n),Drag(1:n));
xlabel({'Time (s)'});
ylabel({'Drag (N)'});
title({'Drag Force'});
% Figure 9
subplot(5,2,2)
plot(Distance(1:n),Fn(1:n));
xlabel({'Distance (m)'});
ylabel({'Normal Force (N)'});
title({'Normal Force'});
% Figure 10
subplot(5,2,1)
plot(t(1:n),Vm(1:n));
xlabel({'Time (s)'});
ylabel({'Vm(n) (m/s)'});
title({'Velocity Magnitude'}); 댓글을 달려면 로그인하십시오.

R2020a

### Community Treasure Hunt

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

Start Hunting!