-
Notifications
You must be signed in to change notification settings - Fork 0
/
PhaseTwoODE.m
103 lines (83 loc) · 2.98 KB
/
PhaseTwoODE.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
% --------------------
% ID 109
% ASEN 2012-001
% Lab 2
% Purpose:
% erve as the defining set of differential equations to be solved during
% Phase 2 of rocket flight
% Inputs: t,z; global variables
% Outputs: dPhase1dt = [mDotRocket,accZ,accX,velZ,velX]';
% Last modified: 12/4 - ID 109 - Initial Release
% Last modified: 12/6 - ID 109 - Final Release. All requirments met
% --------------------
function dPhase2dt = PhaseTwoODE(t,z)
% Sets up the system of ODEs for the second phase
% Rocket is thrusting with the air
% Pull global variables
global g gamma pAtm rhoWater rhoAir cDrag cDischarge nozzleArea pAirInitial volBottle volWaterInitial volAirInitial theta railLength p0 sectionBottle mAirInitial mBottleEmpty R
% Setting velocity in to be the inegral of acceleration
velZ = z(2);
velX = z(3);
vel = sqrt((velX^2)+(velZ^2));
% Setting rocket mass to be the integral of mDotRocket
mass = z(1);
% Equation for determining the air pressure in the bottle
pEnd = p0*((volAirInitial/volBottle)^gamma);
mAir = mass - mBottleEmpty;
p = ((mAir/mAirInitial)^gamma)*pEnd;
% Defining gas properties
rho = mAir/volBottle;
Temp = p/(rho*R);
% Heading is determined by velocity
headingZ = velZ/vel;
headingX = velX/vel;
% Calculate critical pressure
pCrit = p*((2/(gamma+1))^(gamma/(gamma-1)));
% Checking if the flow is choked
if pCrit > pAtm
% Flow is choked
% Computing the temperature at nozzle exit
Te = (2/(gamma+1))*Temp;
% Equation for determining exit velocity with a choked flow
vE = sqrt(gamma*R*Te);
% Defining pExit
pExit = pCrit;
% Defining rhoExit
rhoExit = pExit/(R*Te);
else
% The flow is not choked
% Computing the exit Mach number
machExit = sqrt((((p/pAtm)^((gamma-1)/gamma))-1)*(2/(gamma-1)));
% Computing temperature at nozzle exit
Te = Temp/(1+((gamma-1)/2)*(machExit^2));
% Equation for determining exit velocity in a non-choked flow
vE = machExit*sqrt(gamma*R*Te);
% Defining pExit
pExit = pAtm;
% Defining rhoExit
rhoExit = pAtm/(R*Te);
end
% Defining mDotAir
mDotAir = cDischarge*rhoExit*nozzleArea*vE;
% Equation for thrust from pressurized air
forceThrust = (mDotAir*vE)+((pExit-pAtm)*nozzleArea);
if forceThrust < 0
forceThrust = 0;
end
forceZThrust = forceThrust*cos(atan(headingZ/headingX));
forceXThrust = forceThrust*sin(atan(headingZ/headingX));
% Equation for drag
forceDrag = -(rhoAir/2)*(vel^2)*cDrag*sectionBottle;
forceZDrag = -(rhoAir/2)*(velZ^2)/((cos(atan(headingZ/headingX)))^2)*cDrag*sectionBottle;
forceXDrag = -(rhoAir/2)*(velX^2)/((cos(atan(headingZ/headingX)))^2)*cDrag*sectionBottle;
% Defining the differential equation for mDot
mDotRocket = -mDotAir;
% Differential equation for rocket acceleration in Z
%accZ = forceZ/mass;
accZ = ((forceThrust+forceDrag)*headingZ/mass) - g;
% Differential equation for rocket acceleration in X
%accX = forceX/mass;
accX = (forceThrust-forceDrag)*headingX/mass;
% Combining in column vector for passing into ode45
dPhase2dt = [mDotRocket,accZ,accX,velZ,velX]';
end