-
Notifications
You must be signed in to change notification settings - Fork 0
/
ME557_Final_Project_NoAirDrag_Script.m
207 lines (165 loc) · 7.17 KB
/
ME557_Final_Project_NoAirDrag_Script.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
%{
ME 557 Paris Gun Final Project.
Model of the Projectile dynamics assuming air drag is negligable
Author: Curran J. Robertson, Kyden F. DeGross, Roger Nakagawa
Professor: Dr. Daniel Rederth
Description: Script calculates and plots the dynamics of the Paris Gun
Projectile for both the X and Y directions.
OUTPUTS:
Figure 1:
x-position of the Paris Gun projectile as a function of time.
Velocity in the x-direction of the Paris Gun projectile as a
function of time.
Velocity in the x-direction of the Paris Gun projectile as a
function of the x-position.
Figure 2:
y-position of the Paris Gun projectile as a function of time
Velocity in the y-direction of the Paris Gun projectile as a
function of time
Velocity in the y-direction of the Paris Gun projectile as a
function of the x-position
y-position of hte Paris Gun projectile as a function of the
x-position
%}
clear; clc; close all
%% Constants
v0 = 1640; % initial velocity (m/s)
theta = 55; % Launch Angle (degrees)
g = 9.81; % acceleration due to gravity (m/s^2)
%% Solving for time of flight (TOF)
tpeak = (v0*sind(theta))/g;
tflight = 2*tpeak;
%% Solving for Maximum Range in x-direction
xmax = v0*cosd(theta)*tflight; % Maximum distance traveled in the x-direction (m)
xmaxkm = xmax/1000;
step = 0.1; % step size (m)
timevector = 0:step:tflight; % time vector (m)
ypositionvectorairdrag = zeros(1,length(timevector));
yvelocityvectorairdrag = zeros(1,length(timevector));
%% Descritized Vectors for Dynamics without Air Drag
xpositionvectornoairdrag= v0*cosd(theta)*timevector;
ypositionvectornoairdrag = v0*sind(theta)*timevector-0.5*g*(timevector.^2);
xvelocityvectornoairdrag = v0*cosd(theta)+0*timevector;
yvelocityvectornoairdrag = v0*sind(theta)-g*timevector;
%% Calculation of X direction Air Drag
cd1a = 0.0027; %perseconds
xpositionvectorairdrag(1:1820)= (v0*cosd(theta)/cd1a)*(1-exp(-cd1a*timevector(1:1820)));
xvelocityvectorairdrag(1:1820) = (v0*cosd(theta)*exp(-cd1a*timevector(1:1820)));
%% Stage 1 Equations (y) 0<Vy<343 Air Drag
%Vy>M3
ypositionvectorairdrag(1:242) = (((v0*sind(theta)*cd1a)+g)/cd1a^2)*(1-exp(-cd1a*timevector(1:242)))-(g*timevector(1:242)/cd1a);
yvelocityvectorairdrag(1:242) = (-g/cd1a)+((cd1a*v0*sind(theta)+g)/cd1a)*exp(-cd1a*timevector(1:242));
%M2<Vy<M3
cd1b = 0.04;
theta1b = 49.4;
ypositionvectorairdrag(242:320) = (((343*3*sind(theta1b)*cd1b)+g)/cd1b^2)*(1-exp(-cd1b*timevector(1:79)))-(g*timevector(1:79)/cd1b)+ypositionvectorairdrag(242);
yvelocityvectorairdrag(242:320) = (-g/cd1b)+((cd1b*343*3*sind(theta1b)+g)/cd1b)*exp(-cd1b*timevector(1:79))+250;
%M1<Vy<M2
cd1c = 0.08;
theta1c = 38.5;
ypositionvectorairdrag(321:389) = (((2*343*sind(theta1c)*cd1c)+g)/cd1c^2)*(1-exp(-cd1c*timevector(1:69)))-(g*timevector(1:69)/cd1c)+ypositionvectorairdrag(319);
yvelocityvectorairdrag(321:389) = (-g/cd1c)+((cd1c*2*343*sind(theta1c)+g)/cd1c)*exp(-cd1c*timevector(1:69))+329.1;
%% Stage 2 Equations (y) Air Drag
cd2 = 0.0027;
ypositionvectorairdrag(390:885)=(-log(cos(timevector(1:496)*g*cd2))/cd2)+ypositionvectorairdrag(389);
yvelocityvectorairdrag(390:885)=(tan(timevector(1:496)*sqrt(g*cd2))*g/sqrt(g*cd2));
%% Stage 3 & 4
ypositionvectorairdrag(885:910)= 4.2269e+04 + 0.5*(24)*timevector(1:26);
yvelocityvectorairdrag(885:910) = 24-g*timevector(1:26);
ypositionvectorairdrag(910:935)= 4.23e+04 + 0.5*(-24)*timevector(1:26);
yvelocityvectorairdrag(910:935) = 0+g*timevector(1:26);
%% Stage 5
%% Stage 6
%M1<Vy<M2
cd1c = 0.08;
theta1c = 38.5;
ypositionvectorairdrag(321:389) = (((2*343*sind(theta1c)*cd1c)+g)/cd1c^2)*(1-exp(-cd1c*timevector(1:69)))-(g*timevector(1:69)/cd1c)+ypositionvectorairdrag(319);
yvelocityvectorairdrag(321:389) = (-g/cd1c)+((cd1c*2*343*sind(theta1c)+g)/cd1c)*exp(-cd1c*timevector(1:69))+329.1;
%M2<Vy<M3
cd1b = 0.04;
theta1b = 49.4;
ypositionvectorairdrag(242:320) = (((343*3*sind(theta1b)*cd1b)+g)/cd1b^2)*(1-exp(-cd1b*timevector(1:79)))-(g*timevector(1:79)/cd1b)+ypositionvectorairdrag(242);
yvelocityvectorairdrag(242:320) = (-g/cd1b)+((cd1b*343*3*sind(theta1b)+g)/cd1b)*exp(-cd1b*timevector(1:79))+250;
%Vy>M3
ypositionvectorairdrag(1:242) = (((v0*sind(theta)*cd1a)+g)/cd1a^2)*(1-exp(-cd1a*timevector(1:242)))-(g*timevector(1:242)/cd1a);
yvelocityvectorairdrag(1:242) = (-g/cd1a)+((cd1a*v0*sind(theta)+g)/cd1a)*exp(-cd1a*timevector(1:242));
%% Plots for projectile motion with both no airdrag(blue) and airdrag(orange)
% X-position vs Time
figure(1)
subplot(3,1,1)
plot(timevector,xpositionvectornoairdrag);
hold on
subplot(3,1,1)
plot(timevector(1:1820),xpositionvectorairdrag);
title('x(t) of the Paris Gun Projectile');
xlabel('time (s)');
ylabel('x-position (m)');
legend('No Air Drag','Air Drag');
% X-velocity vs Time
subplot(3,1,2)
plot(timevector,xvelocityvectornoairdrag);
title('Vx(t) of the Paris Gun Projectile');
xlabel('time (s)');
ylabel('x-velocity (m/s)');
hold on;
subplot(3,1,2)
plot(timevector(1:1820),xvelocityvectorairdrag);
legend('No Air Drag','Air Drag');
% X-velocity vs X-position
subplot(3,1,3)
plot(xpositionvectornoairdrag,xvelocityvectornoairdrag);
title('Vx(x) of the Paris Gun Projectile');
xlabel('x-position (m)');
ylabel('x-velocity (m/s)');
hold on
subplot(3,1,3)
plot(xpositionvectorairdrag,xvelocityvectorairdrag);
legend('No Air Drag','Air Drag');
% Figure 2 is y components and total plot
% Y-position vs Time
figure(2)
subplot(3,1,1)
plot(timevector,ypositionvectornoairdrag);
title('y(t) of the Paris Gun Projectile');
xlabel('time (s)');
ylabel('y-position (m)');
hold on
subplot(3,1,1)
plot(timevector,ypositionvectorairdrag);
legend('No Air Drag','Air Drag');
% Y-velocity vs Time
subplot(3,1,2)
plot(timevector,yvelocityvectornoairdrag);
title('Vy(t) of the Paris Gun Projectile');
xlabel('time (s)');
ylabel('y-velocity (m/s)');
hold on
subplot(3,1,2)
plot(timevector,yvelocityvectorairdrag);
legend('No Air Drag','Air Drag');
% Y-velocity vs Y-position
subplot(3,1,3)
plot(ypositionvectornoairdrag,yvelocityvectornoairdrag);
title('Vy(y) of the Paris Gun Projectile');
xlabel('y-position (m)');
ylabel('y-velocity (m/s)');
hold on
subplot(3,1,3)
plot(ypositionvectorairdrag,yvelocityvectorairdrag);
legend('No Air Drag','Air Drag');
% Y-position vs X-position (Total Flight)
figure(3)
plot(xpositionvectornoairdrag,ypositionvectornoairdrag)
title('y(x) of the Paris Gun Projectile')
xlabel('x-position (m)')
ylabel('y-position (m)')
hold on
plot(xpositionvectorairdrag,ypositionvectorairdrag(1:1820))
plot(xpositionvectorairdrag(242),ypositionvectorairdrag(242),'kx');
plot(xpositionvectorairdrag(320),ypositionvectorairdrag(320),'kx');
plot(xpositionvectorairdrag(389),ypositionvectorairdrag(389),'kx');
plot(xpositionvectorairdrag(885),ypositionvectorairdrag(885),'kx');
plot(xpositionvectorairdrag(910),ypositionvectorairdrag(910),'kx');
plot(xpositionvectorairdrag(935),ypositionvectorairdrag(935),'kx');
plot(xpositionvectorairdrag(242),ypositionvectorairdrag(242),'kx');
legend('No Air Drag','Air Drag','Stage 1a','Stage 1b','Stage 1c','Stage 2','Stage 3', 'Stage 4','Stage 5a');