project 2 - bottle rocket model - wordpress.com · 2020. 1. 8. · asen 2012 project 2 - bottle...

26
ASEN 2012 Project 2 - Bottle Rocket Model Computational Project 8 Dec 2017 ID: 224 This report discusses the use of the built-in MATLAB function ode45 to numerically solve a system of differential equations modeling the flight of a bottle rocket. The rocket has adjustable input parameters of volume of water, air pressure, drag coefficient, and launch angle. Initially, a verification case is matched to ensure proper functionality of ode45, and then parameters are determined such that the bottle rocket will go 75 ± .1 m in the horizontal direction before impacting the ground again. Nomenclature γ = Ratio of Specific Heats for Air: 1.4 ρ air,ambient = Density of Ambient Air: 0.961 [ kg m 3 ] ρ w = Density of Water: 1000 [ kg m 3 ] θ = Initial Launch Angle, measured in radians counterclockwise from horizontal +x ~ D = Drag Force [N] ~ F = Thrust Force [N] ~ W = Weight Force [N] C D = Drag Coefficient c d = Discharge Coefficient (Constant for this Project): 0.8 D bottle = Diameter of the Bottle [cm] D throat = Diameter of Throat: 2.1 [cm] g = Acceleration due to Gravity: 9.81 [ m s 2 ] ls = Length of the Test Stand [m] M bottle = Mass of the Empty Bottle (with fins): 0.15 [kg] p = Pressure in Rocket at any time [Pa] (all pressures are converted to Pa for calculations) p * = Critical Pressure [Pa] p e = Pressure of Exhaust [Pa] p i air = Initial Gage Pressure in Rocket [psi] p a = Ambient Atmospheric Pressure: 12.1 [psi] p end = Pressure of Air at End of Phase 1 [Pa] q = Dynamic Pressure (q = 1 2 ρv 2 )[ kg m 3 * m 2 s 2 = Pa] R = Gas Constant for Air: 287 [ J kg*K ] T i air = Initial Temperature of the Air [K] T end = Temperature of the Air at the End of Phase 1 [K] v = Volume of Air in the Rocket at any time t [m 3 ] v 0 = Initial Velocity of the Rocket [ m s ] v b = Volume of the Empty Bottle: 0.002 [m 3 ] V e = Exit Speed of Fluid from the Nozzle [ m s ] V i water = Initial Volume of the Water [m 3 ] ASEN 2012 1 of 26 Fall 2017

Upload: others

Post on 20-Jan-2021

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Project 2 - Bottle Rocket Model - WordPress.com · 2020. 1. 8. · ASEN 2012 Project 2 - Bottle Rocket Model Computational Project 8 Dec 2017 ID: 224 This report discusses the use

ASEN 2012Project 2 - Bottle Rocket Model

Computational Project8 Dec 2017

ID: 224

This report discusses the use of the built-in MATLAB function ode45 to numericallysolve a system of differential equations modeling the flight of a bottle rocket. The rockethas adjustable input parameters of volume of water, air pressure, drag coefficient, andlaunch angle. Initially, a verification case is matched to ensure proper functionality ofode45, and then parameters are determined such that the bottle rocket will go 75± .1 m inthe horizontal direction before impacting the ground again.

Nomenclature

γ = Ratio of Specific Heats for Air: 1.4ρair,ambient = Density of Ambient Air: 0.961 [ kgm3 ]

ρw = Density of Water: 1000 [ kgm3 ]θ = Initial Launch Angle, measured in radians counterclockwise from horizontal +x~D = Drag Force [N]~F = Thrust Force [N]~W = Weight Force [N]CD = Drag Coefficientcd = Discharge Coefficient (Constant for this Project): 0.8Dbottle = Diameter of the Bottle [cm]Dthroat = Diameter of Throat: 2.1 [cm]g = Acceleration due to Gravity: 9.81 [ms2 ]ls = Length of the Test Stand [m]Mbottle = Mass of the Empty Bottle (with fins): 0.15 [kg]p = Pressure in Rocket at any time [Pa] (all pressures are converted to Pa for calculations)p∗ = Critical Pressure [Pa]pe = Pressure of Exhaust [Pa]piair = Initial Gage Pressure in Rocket [psi]pa = Ambient Atmospheric Pressure: 12.1 [psi]pend = Pressure of Air at End of Phase 1 [Pa]

q = Dynamic Pressure (q = 12ρv

2) [ kgm3 ∗ m2

s2 = Pa]

R = Gas Constant for Air: 287 [ Jkg∗K ]

T iair = Initial Temperature of the Air [K]Tend = Temperature of the Air at the End of Phase 1 [K]v = Volume of Air in the Rocket at any time t [m3]v0 = Initial Velocity of the Rocket [ms ]vb = Volume of the Empty Bottle: 0.002 [m3]Ve = Exit Speed of Fluid from the Nozzle [ms ]V iwater = Initial Volume of the Water [m3]

ASEN 2012 1 of 26 Fall 2017

Page 2: Project 2 - Bottle Rocket Model - WordPress.com · 2020. 1. 8. · ASEN 2012 Project 2 - Bottle Rocket Model Computational Project 8 Dec 2017 ID: 224 This report discusses the use

x0 = Initial Position in x [m]z0 = Initial Position in z [m]...[1]

ASEN 2012 2 of 26 Fall 2017

Page 3: Project 2 - Bottle Rocket Model - WordPress.com · 2020. 1. 8. · ASEN 2012 Project 2 - Bottle Rocket Model Computational Project 8 Dec 2017 ID: 224 This report discusses the use

I. Introduction

Figure 1: Free Body Diagram of Rocket This figure shows howall the forces act on the bottle rocket. Note thrust and drag are alwaysopposing forces.

The goal of this lab is to model theflight of a bottle rocket using numericalintegration within the built-in functionode45 in MATLAB. There are a num-ber of thermodynamic and aerodynamicequations governing the flight propertiesof the bottle rocket. To simplify the prob-lem, the rocket is assumed to move in aplane (thus having only two dimensionsx and z). The rocket’s motion be ana-lyzed through a numerical analysis of theforces acting on the rocket. Throughoutthe flight, the net force on the rocket isgiven by Σ ~Forces = ~F + ~D+ ~W where ~Fis the thrust vector, ~D is the drag vector,and ~W is the weight of the rocket. SeeFig. 1 for the free body diagram of therocket. Since these are vectors, these canbe broken down into their two linearlyindependent components:

Σ ~Forcesx = cos(θ) ∗ |~F | − cos(θ) ∗ | ~D|and

Σ ~Forcesz = sin(θ) ∗ |~F | − sin(θ) ∗ | ~D| − |W |). The problem then boils down to double integrating these force equations to get displacement of the rocket.In every case, the magnitude of the drag force is given by:

D = qCDAB =ρair,ambient

2v2CDAB (1)

Overall, the rocket flight can be divided into three phases. The first phase is characterized by waterpropulsion. Air pressure inside the bottle pushes water out the nozzle, and conservation of momentum withNewton’s third law explains the reaction force propelling the rocket. The second is defined by the excess airin the chamber rushing out the nozzle, providing thrust, and the third phase is a ballistic phase where theair inside the rocket has equalized with the atmosphere and the rocket acts as a ballistic projectile with nothrust. The specific equations governing each state are given below.

I.A. Phase 1

During this phase of flight, only water leaves the rocket, so the mass of the air remains constant. However,its volume increases. Thus the pressure in the rocket decreases with time and can be found with

p

piair=

(viairv

)γ(2)

Additionally, the mass flow rate (also the rate of change in mass of the rocket because water is the onlymass leaving the system) of the water out of the bottle is given by

m = cdρwAtVe (3)

The thrust of the rocket isF = mVe + (pe − pa)At (4)

.As given in the lab description, assuming water to be incompressible and applying Bernoulli’s equation,

the exhaust velocity is

Ve =

√p− paρw

(5)

ASEN 2012 3 of 26 Fall 2017

Page 4: Project 2 - Bottle Rocket Model - WordPress.com · 2020. 1. 8. · ASEN 2012 Project 2 - Bottle Rocket Model Computational Project 8 Dec 2017 ID: 224 This report discusses the use

The change in volume of the air is given by

dv

dt= cdAtVe = cdAt

√2(p− pa)

ρw= cdAt

√√√√ 2

ρw

[p0

(v0v

)γ− pa

](6)

I.B. Phase 2

Once all the water has been expelled, some new equations begin to govern the rocket. The air is acompressible flow now while the water before was incompressible and allowed some simplification. Continuingthe naming convention of the lab description and as explicated in the Nomenclature, we can calculate theconstants for the pressure and temperature at the end of phase 1.

pend = pairi

(viairvB

)γ; Tend = T iair

(viairvB

)γ−1

(7)

Since we again assume the air to expand isentropically out the nozzle, the pressure at a time t can be foundwith

p

pend=

(mair

miair

)γ(8)

and similarly the density and temperature are simple calculations:

ρ =mair

vB; T =

p

ρR(9)

Another necessary component is the critical pressure. This is defined to be

p∗ = p

(2

γ + 1

) γ(γ−1)

(10)

This pressure is used to determine whether flow out the nozzle is sonic or subsonic and thus which set ofequations must be used to calculate thrust.

Flow Choked,Sonic Flow: P∗ > PaIn the case of choked flow, use the following:

Ve =√γRTe

Te =

(2

γ + 1

)T

ρe =peRTe

pe =p∗ (11)

Flow Not Choked, Subsonic Flow: p∗ ≤ paWhen the flow is not choked, the following are used. Note that this set includes the mach number.

Calculating the mach number of the exit flow is necessary because it is no longer just 1. It is required to

ASEN 2012 4 of 26 Fall 2017

Page 5: Project 2 - Bottle Rocket Model - WordPress.com · 2020. 1. 8. · ASEN 2012 Project 2 - Bottle Rocket Model Computational Project 8 Dec 2017 ID: 224 This report discusses the use

find the temperature and pressure of the flow.

pe = pa

Me =

√√√√[( p

pa

) γ−1γ

− 1

]2

γ − 1

Te =T(

1 + γ−12 Me

2

)ρe =

paRTe

Ve = Me

√γRTe

(12)

For both cases, the mass flow out of the rocket is merely the air and thus

mR = mair = cdρeAtVe (13)

Thrust in this phase is calculated by

F = mairVe + (pe − pa)At (14)

I.C. Phase 3

Phase three is by far the simplest of the phases. Since the rocket acts as a a ballistic projectile, there isno thrust and the mass of the rocket is close to the mass of the bottle.[2]

II. Methodology

To use MATLAB to model the flight of the bottle rocket, a simple system of functions was used. SeeAppendix A for the flow chart of the algorithm represented visually. In essence, the script does four maintasks to accomplish the tasks required. First, the verification case is matched. Next, the parameter spaceis explored, and then three example trajectories are calculated. Of these three, one is the target distancegetting the maximum height, one is the target distance getting allowing the minimum height obtained, andthe third is simply the approximate maximum distance of the rocket.

II.A. The ODE Function Itself

Before any of the above can be done, a function representing the system of differential equations modellingflight is required. This function, named makeThatRocketFlyBoys handles all three phases in one function.To do so, the first parameter calculated is the pressure. To know which equation to use (essentially whichphase the rocket is in), first the volume of the air is compared to the volume of the bottle. If the volume ofthe air matches the volume of the bottle, next the density of the air in the bottle is compared to the densityof the atmosphere. When the density of air in the rocket is greater than the density of the atmosphere, therocket is in phase two. If neither condition is met, the rocket is in phase 3.

Next the function calculates speed and heading at that instance of time. Then a methodical approach isused to assign the numbers into the differential vector returned from the function. To keep the explanationsimple, the relevant equations are all listed above, so this function ultimately compiles these to appropriateplaces to calculate for each time the change in x position, z position, x velocity, z velocity, total mass of therocket, volume of the air, and mass of the air.

II.B. The Plotting Function

The plotting function is the other large building block for this script. Simply, this function takes all thedata passed out of an ode45 solution and plots it in pertinent ways. The function makes a tab group withthree plots. The first plot is the informational overview for the flight. This tab has six subplots: trajectory,

ASEN 2012 5 of 26 Fall 2017

Page 6: Project 2 - Bottle Rocket Model - WordPress.com · 2020. 1. 8. · ASEN 2012 Project 2 - Bottle Rocket Model Computational Project 8 Dec 2017 ID: 224 This report discusses the use

thrust over time, horizontal velocity over time, vertical velocity over time, a plot of both mass of the rocketand the air over time, and finally a plot of the volume of air over time. Though not required for the lab,these are interesting nonetheless.

The second plot is a larger version of the trajectory. Position in z is plotted over position in x. Also, themaximum height and maximum distance are added onto the plot.

The third plot is the thrust profile for the launch. The times for when the rocket switches phases arealso plotted (if ode45 ever calculates that the phase switches). The profile is zoomed in to the more relevanttime window to observe thrust: before the rocket is ballistic.

II.C. Verification

The first main task of the script is to duplicate a verification case. With the same input parameters andconstants, this script will run ode45 on our function and then plot the results for compare.

II.D. Exploring Parameter Space

To see how the parameters affect the rocket flight, each parameter is varied in turn. The results aresub-plotted so each parameter’s effect on distance can be observed. For each parameter, a vector of 30elements ranging from the minimum allowable value of that parameter to the maximum is created. A forloop then calculates the trajectory for each element in the array keeping the other initial conditions constantto that of the verification phase. The max distance from each calculation is extracted and saved for plottingagainst the parameter later.

First the air pressure’s effect is sought. Air pressure is allowed to vary from 0 to 100 psi. The rupturepressure of a two-liter bottle is 150 psi [3]. Using a safety factor of 1.5, the maximum allowable gaugepressure is 100 psi.

The next parameter of study is the coefficient of drag. The coefficient of drag varies from .3 to .5 [2], sothe process is repeated for coefficients of drag in this range.

After coefficient of drag, the launch angle is varied. Launch angle ranges from 0◦ to 90◦. These anglesspan the first quadrant, but this lab is only concerned with the first quadrant, so these are all the anglesneeded.

Finally, the initial volume of water is allowed to vary from 0 to .002 m3, the two physical limits of howmuch water can be put into the bottle rocket.

II.E. Getting The Target Distance/Other Trajectories

Once the effect of the parameters is known, the script calculates parameter sets to get 75 m in distance.The values of the parameters corresponding to greatest distance are extracted for water volume, pressureand drag coefficient. Taking these as parameters to remain constant, the launch angle can be varied until 75m with the tolerance can be achieved. Once this is done with an angle above 45◦ giving the target distancewith the maximum possible height in the trajectory, and once with the angle less than 45◦. This gives the”less safe” approach, but the target distance is achieved.

For the sake of curiosity, after parameters for the target distance are found, the script finds the maximumpossible distance by simply taking the corresponding parameters to their respective maximum distance.

III. Results

When the script runs, a large tab group with a lot of data is created. Below are the relevant plots andsets of parameters.

Table 1: Target Distance with Maximum Height Achieved

Distance [m] Max Height [m] Pressure [psi] Launch Angle [◦] Initial Water Volume [m3] Coefficient of Drag

75.00 88.37 100 72.96 .000621 .3

ASEN 2012 6 of 26 Fall 2017

Page 7: Project 2 - Bottle Rocket Model - WordPress.com · 2020. 1. 8. · ASEN 2012 Project 2 - Bottle Rocket Model Computational Project 8 Dec 2017 ID: 224 This report discusses the use

(a) Trajectory This is the calculated trajectory of the rocketwith the verification parameters.

(b) Thrust Profile This is the thrust profile for the rocketwhile in the first two phases. Note the delineation of phases.

Figure 2: Verification Data

Table 2: Target Distance with Minimum Height Achieved

Distance [m] Max Height [m] Pressure [psi] Launch Angle [◦] Initial Water Volume [m3] Coefficient of Drag

75.01 4.78 100 12.61 .000621 .3

Table 3: Maximum Range Achieved

Distance [m] Max Height [m] Pressure [psi] Launch Angle [◦] Initial Water Volume [m3] Coefficient of Drag

142.72 48.98 100 43.4 .000621 .3

Figure 3: Exploring the Parameter Space This plot shows how rocket distance depends on each parameterallowed to vary: initial water volume, initial air pressure, coefficient of drag, and initial launch angle.

ASEN 2012 7 of 26 Fall 2017

Page 8: Project 2 - Bottle Rocket Model - WordPress.com · 2020. 1. 8. · ASEN 2012 Project 2 - Bottle Rocket Model Computational Project 8 Dec 2017 ID: 224 This report discusses the use

(a) Trajectory, Maximum Height This is the calculatedtrajectory of the rocket for the target distance. This trajectoryhits the maximum possible height on its way to 75 meters.

(b) Trajectory, Minimum Height This is the trajectory ofthe rocket going 75 meters but hitting the minimum verticalheight.

Figure 4: Hitting Target Distance

Figure 5: Maximum Possible Distance This is the trajectory of the rocket if all the parameters are chosen toallow the rocket the maximum possible distance.

ASEN 2012 8 of 26 Fall 2017

Page 9: Project 2 - Bottle Rocket Model - WordPress.com · 2020. 1. 8. · ASEN 2012 Project 2 - Bottle Rocket Model Computational Project 8 Dec 2017 ID: 224 This report discusses the use

IV. Discussion

IV.A. Verification Case

The verification case data is shown in Fig 2. The trajectory of the rocket indicates that the rocket reachesa maximum height of 17.13 meters and a distance of 60.30 meters. These values are within the tolerance forthe verification case. The thrust for the verification case also matches closely the supplied thrust profile, sothe differential equation system is functioning.

IV.B. Exploring the Parameters

As shown in Fig. 3, the independent effect of each parameter on range can be studied.In the case of pressure, the range of the rocket increases with initial air pressure. Though the curve does

not appear to be linear, the plot is always increasing which means any increase in pressure will correspondto an increase in distance of the rocket. For the sake of curiosity, plotting the pressure in this fashion up to1000 psi indicates this trend continues, though the distance-pressure curve is definitely concave down.

When the coefficient of drag is allowed to vary, the distance appears to be a near-linear function of thecoefficient of drag. As expected, higher coefficients of drag reduce the total distance of the rocket. The bestcase for the drag is as low as possible, for the case of bottle rockets, this would be around a drag coefficientof 0.3.

The launch angle corner of the plot suggests that the optimal launch angle is between 40 and 50 (infact it is calculated to be 43◦). This makes sense actually, since the rocket has a moment created by therelationship between its center of pressure and center of gravity. Essentially the rocket’s ability to resistturning creates an effect apparently for the rocket to travel farther at an angle just over 45◦. Since there isdrag acting on the rocket, the angle just less than 45 should be the best launch angle, which it is.

Finally, the variation in the initial water volume indicates the optimal water volume to be around .0006m3. The distance-volume curve looks like it may be modelled with the left half of a cubic function orsomething like this. It makes sense, however, that the best initial water volume is not one of the end casesof 0 m3 or .002 m3. If no water is in the rocket at the start, the rocket is light but has only air thrust forpropulsion. If the bottle is completely full, there is not enough air in the bottle to push the water out fastenough. Once the water starts to leave the bottle, the air pressure decreases quickly and the thrust profiledrops steeper in this case. Moreover, the rocket is heavier and requires more force to move in general, sothis middle of the range value must be the balance between the more powerful thrust from the water andthe extra weight cost of the water.

IV.C. Hitting the Target Distance

Since an iterative solution is used to calculate the initial launch angle to hit 75 meters, a precise angleallows each 75-m trajectory to hit 75 ± .01 m. This range of tolerance is well within the required toleranceof 1 meter. As seen in tables 1 and 2, some sets of parameters to hit 75 meters are similar. In both cases, theinitial pressure used was 100 psi. The initial water volume was .000621 m3, and the coefficient of drag was0.3. The angle for going the maximum height was around 75◦. This makes sense; if the rocket is launchedcloser to straight up, it will go higher. The angle for keeping vertical height down was around 9◦. This alsomakes sense; the low angle makes the rocket similar to projectiles fired from a cannon, say.

V. Conclusions

Ultimately, the four parameters of study have complex yet logical relationships to total distance. Pressureis an increasing function for all pressures of study, distance over coefficient of friction is a decreasing functionalways, and both the water volume and launch angle are concave down with a maximum value somewhereon the interior of the studied domain.

To make a rocket go 75 meters, input parameters are summarized in Table 1 and Table 2.

ASEN 2012 9 of 26 Fall 2017

Page 10: Project 2 - Bottle Rocket Model - WordPress.com · 2020. 1. 8. · ASEN 2012 Project 2 - Bottle Rocket Model Computational Project 8 Dec 2017 ID: 224 This report discusses the use

References

1ASEN 2012 Project 2: Verification Constants, Inputs, and Trajectory. CU, 2017. PDF.2ASEN 2012 Project 2: Bottle Rocket Design. CU, 2017. PDF.3Becker, Andrea. “How Much Pressure Can a Two Liter Bottle Handle?” Accessed 4 Dec 2017.

http://education.seattlepi.com/much-pressure-can-two-liter-bottle-handle-6313.html

Appendix A: Algorithm

Overall Structure:

Project2.m

Set-up:Clear,

clc, defineconstants

SolveVerification

Example

ExploreParameter

Space

CalculateParametersfor TargetDist, Max

height

CalculateParametersfor TargetDist, Min

height

CalculateMax

PossibleDistance

End

Each Process in greater detail:

† † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † †

SolveVerification

Example

Set upConstants

Use ode45to Solve

Plot theInformation

Done

† † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † †

ExploreParameter

SpacePressure

Coefficientof Drag

LaunchAngle

WaterVolume

Done

For ManyValues inRange ofinterest

in range:

Use ode45to SolveThis Pa-

rameter Set

Plot theMax

Distancesfrom EachVariation

of theParameter

For ManyValues inRange ofinterest

in range:

Use ode45to SolveThis Pa-

rameter Set

Plot theMax

Distancesfrom EachVariation

of theParameter

For ManyValues inRange ofinterest

in range:

Use ode45to SolveThis Pa-

rameter Set

Plot theMax

Distancesfrom EachVariation

of theParameter

For ManyValues inRange ofinterest

in range:

Use ode45to SolveThis Pa-

rameter Set

Plot theMax

Distancesfrom EachVariation

of theParameter

ASEN 2012 10 of 26 Fall 2017

Page 11: Project 2 - Bottle Rocket Model - WordPress.com · 2020. 1. 8. · ASEN 2012 Project 2 - Bottle Rocket Model Computational Project 8 Dec 2017 ID: 224 This report discusses the use

† † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † †

TargetDistance,

Max HeightAND Min

Height

Guess atInitial Angle

UntilRange is inTolerance:

Get Rangewith ode45

CheckRange.Adjust

Angle Ap-propriately

PlotInformation

of FinalParameters

Done

† † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † †

MaximumDistance

Get Pa-rameters

MaximizingDistance

fromExploration

Solve withThese

Parameters

Plot theInformation

for thisFlight ofGLORY

Done

† † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † †

System ofDifferentialEquations:

Passedinto ode45

Get Accessto GlobalVariables

CalculatePressure

CalculateVelocity and

Heading

Calculate dydt

for EveryTracked

Parameter:xz

vxvzmR

Vair

mair

Check ifRocket is

On GroundReturn

† † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † †

Plottingthe ode45Results

Set UpGlobal

Variables

CalculateRemainingRequired

ParametersNot Given

Plug intoode45

to Solve

CalculateThrust

over FlightReturn

† † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † † †

ASEN 2012 11 of 26 Fall 2017

Page 12: Project 2 - Bottle Rocket Model - WordPress.com · 2020. 1. 8. · ASEN 2012 Project 2 - Bottle Rocket Model Computational Project 8 Dec 2017 ID: 224 This report discusses the use

Appendix B: Engineering Method

Problem Solving Method:Purpose: To model the trajectory of a bottle rocket and determine how various parameters affect the

expected flight pathGiven: All verification parametersGoal: A model that can take input parameters and predict trajectory of a bottle rocket. Also, calculate

parameters for a goalAssumptions: Air expansion in rocket is isentropic (and thus adiabatic) Bottle Rocket will only have

horizontal and vertical components g = 9.81m/s = about constant over altitude of bottle rocket Giveninitial temperature is same inside bottle and out

Sketch: NAFundamental Principles: ode45, Aerodynamic nozzles and bodiesAlternate Approaches: Could try numerical integration ourselves... Could break ode45 into multiple

functions for each phaseStep-by-Step Algorithm: See flow chartCheck with Simple Version: Solved Verification phaseReality Check: Yep, our solution makes sense. The rocket will hit 75 m in a couple ways.

ASEN 2012 12 of 26 Fall 2017

Page 13: Project 2 - Bottle Rocket Model - WordPress.com · 2020. 1. 8. · ASEN 2012 Project 2 - Bottle Rocket Model Computational Project 8 Dec 2017 ID: 224 This report discusses the use

Appendix C: MATLAB Code

Below are the script and functions used to explore this rocket trajectory.

1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%2 %3 % READ ME4 %5 % This s c r i p t runs a model o f a b o t t l e rocke t f o r ASEN 2012 with P r o f e s s o r6 %Anderson . This s c r i p t models the f l i g h t o f a b o t t l e rocke t . I t f i r s t7 %conf i rms a v e r i f i c a t i o n case , then i t e x p l o r e s the parameter space , and8 %f i n a l l y i t f i n d s parameters f o r a 75−meter f l i g h t . NOTE: Because t h i s9 %s c r i p t does an IMMENSE number o f c a l c u l a t i o n s , i t may take a couple

10 %minutes to run a l l the way through .∗∗∗∗∗∗∗ BE PATIENT ∗∗∗∗∗ . There are no11 %inputs to the s c r i p t . The s c r i p t w i l l c r e a t e s e v e r a l image f i l e s that can12 %get saved in the cur rent d i r e c t o r y . Also , parameters f o r the t a r g e t13 %d i s t anc e are pr in ted in to the command window . F ina l ly , a f i g u r e with tabs14 %conta in ing mi s c e l l aneous p l o t s i s generated . Note : because o f the way15 %images are c rea ted and saved , the f i g u r e w i l l show up be f o r e i t i s done .16 %I t i s f i n i s h e d when there are f i v e main tabs a c r o s s the f i g u r e .17 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%181920 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%21 %Created by ID : 22422 %Created : 12 Nov 201723 %ASEN 201224 %Pro j e c t 225 %Last Modif ied : 8 Dec 201726 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%272829 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%30 %Problem So lv ing Method :31 %32 % Purpose : To model the t r a j e c t o r y o f a b o t t l e rocke t and determine how33 % var i ous paramaters a f f e c t the expected f l i g h t path34 %35 % Given : So many36 %37 % Goal : A model that can take input parameters and p r e d i c t t r a j e c t o r y o f a38 % b o t t l e rocke t . Also , c a l c u l a t e parameters f o r a goa l39 %40 % Assumptions : Air expansion in rocke t i s i s e n t r o p i c ( and thus a d i a b a t i c )41 % Bott l e Rocket w i l l only have h o r i z o n t a l and v e r t i c a l42 % components43 % g = 9.81m/ s = about constant over a l t i t u d e o f b o t t l e rocke t44 % Given i n i t i a l temperature i s same i n s i d e b o t t l e and out45 %46 % Sketch :47 %48 % / | <− Rocket49 % / /50 % \ /\ Forces Acting on i t : Thrust , drag , g rav i ty51 % ( See lab d e s c r i p t i o n f o r52 % b e t t e r sketch )

ASEN 2012 13 of 26 Fall 2017

Page 14: Project 2 - Bottle Rocket Model - WordPress.com · 2020. 1. 8. · ASEN 2012 Project 2 - Bottle Rocket Model Computational Project 8 Dec 2017 ID: 224 This report discusses the use

53 %54 % Fundamental P r i n c i p l e s : ode45 , Aerodynamic n o z z l e s and bod ie s55 %56 % Alte rnate Approaches : Could try numerica l i n t e g r a t i o n o u r s e l v e s . . .57 % Could break ode45 in to mul t ip l e f u n c t i o n s f o r each58 % phase59 %60 % Step−by−Step Algorithm : See f low chart in Report61 %62 % Check with Simple Vers ion : Solved V e r i f i c a t i o n phase63 %64 % Rea l i ty Check : Yep , our s o l u t i o n makes sense . The rocke t w i l l h i t 75 m in65 % a couple ways .66 %67 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%6869 %% DO IT − Set up70 %Be n i c e71 c l e a r ; c l c ; c l o s e a l l ;7273 %% Solve the Verification Case74 %Givens75 P0 = 50 ; %[ p s i ]76 CD = . 5 ;77 Theta0 = pi /4 ; %[ rad ians ]78 VolumeWater = . 0 0 1 ; %[mˆ3 ]79 tspan = [ 0 5 ] ; %[ s ]80 z0 = . 0 1 ; %[m]8182 %Solve the v e r i f i c a t i o n phase83 opts = odeset ( ) ; %Set the maximum step s i z e84 [ t , numbers , t1 , t2 , tImp ] = RocketStuf f (P0 ,CD, Theta0 , VolumeWater , tspan , opts , z0 ) ;85 %Plot misc i n f o f o r comparison86 parent = uitabgroup ;87 v e r i f = uitab ( parent , ' t i t l e ' , ' V e r i f i c a t i o n Case ' ) ;88 p lo tRocke tS tu f f ( t , numbers , t1 , t2 , tImp , ' V e r i f i c a t i o n Case ' , v e r i f ) ;899091 %% Explore Parameter Space92 % Allowed to change i n i t i a l p r e s su r e o f a i r , i n i t i a l volume o f water ,93 % launch angle , and drag c o e f f i c i e n t9495 %%%%%%%%%%%%%%%%%%%%%%%%%%%% KEEP LESS THAN 50 %%%%%%%%%%%%%%%%%%%%%96 samples = 30 ; %Number o f sample po in t s f o r each parameter97 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%9899 %opts = odeset ( ' MaxStep ' , 1 e−3) ;

100 opts = odeset ( ) ;101 %f i g u r e102 cur rent = uitab ( parent , ' t i t l e ' , ' Explor ing Parameter Space ' ) ;103 axes ( ' parent ' , cu r r ent ) ;104 %Pressure105 subplot ( 2 , 2 , 1 )106 maxPres = 150 ; %Maximum Pressure f o r a 2−L b o t t l e [ p s i ]107 s a f e t y = 1 . 5 ;

ASEN 2012 14 of 26 Fall 2017

Page 15: Project 2 - Bottle Rocket Model - WordPress.com · 2020. 1. 8. · ASEN 2012 Project 2 - Bottle Rocket Model Computational Project 8 Dec 2017 ID: 224 This report discusses the use

108 maxPres = maxPres/ s a f e t y ; %Design max pre s su r e based on f a c t o r o f s a f e t y109 distP = ze ro s (1 , samples ) ; %Store s d i s t anc e f o r each pr e s su r e110 pres = l i n s p a c e (1 , maxPres , samples ) ; %Pre s sure s o f i n t e r e s t111 f o r i =1: samples112 [ ˜ , numbers , ˜ , ˜ , ˜ ] = RocketStuf f ( pres ( i ) ,CD, Theta0 , VolumeWater , tspan , opts ,

z0 ) ;113 dis tP ( i )=max( numbers ( numbers ( : , 2 ) >0 ,1) ) ; %Max d i s t anc e114 end115 p l o t ( pres , d i s tP )116 t i t l e ( ' Var ia t ion in Pressure ' )117 x l a b e l ( ' Pres sure g [ p s i ] ' )118 y l a b e l ( ' Distance [m] ' )119120121 %C o e f f i c i e n t o f drag122 subplot ( 2 , 2 , 2 )123 c o e f f s = l i n s p a c e ( . 3 , . 5 , samples ) ;124 distCD = ze ro s (1 , samples ) ; %Store s d i s t ance f o r each drag c o e f f i c i e n t125 f o r i =1: samples126 [ ˜ , numbers , ˜ , ˜ , ˜ ] = RocketStuf f (P0 , c o e f f s ( i ) , Theta0 , VolumeWater , tspan , opts

, z0 ) ;127 distCD ( i )=max( numbers ( numbers ( : , 2 ) >0 ,1) ) ; %Max d i s t anc e128 end129 p l o t ( c o e f f s , distCD )130 t i t l e ( ' Var ia t ion in Drag C o e f f i c i e n t ' )131 x l a b e l ( ' Drag C o e f f i c i e n t ' )132 y l a b e l ( ' Distance [m] ' )133134135 %Launch Angle136 subplot ( 2 , 2 , 3 )137 ang l e s = l i n s p a c e (0 , p i /2 , samples ) ;138 distTh = ze ro s (1 , samples ) ; %Store s d i s t anc e f o r each ang le139 f o r i =1: samples140 [ ˜ , numbers , ˜ , ˜ , ˜ ] = RocketStuf f (P0 ,CD, ang l e s ( i ) , VolumeWater , tspan , opts , z0 )

;141 distTh ( i )=max( numbers ( numbers ( : , 2 ) >0 ,1) ) ; %Max d i s t anc e142 end143 ang l e s=ang l e s / p i ∗180 ; %Convert to degree s because we are humans not robots144 p l o t ( angles , distTh )145 t i t l e ( ' Var ia t ion in Launch Angle ' )146 x l a b e l ( ' Launch Angle [ degree s ] ' )147 y l a b e l ( ' Distance [m] ' )148149150 %I n i t i a l Water Volume151 subplot ( 2 , 2 , 4 )152 volumes = l i n s p a c e (0 , . 00199 , samples ) ;153 distV = ze ro s (1 , samples ) ; %Store s d i s t anc e f o r each i n i t i a l volume154 f o r i =1: samples155 [ ˜ , numbers , ˜ , ˜ , ˜ ] = RocketStuf f (P0 ,CD, Theta0 , volumes ( i ) , tspan , opts , z0 ) ;156 distV ( i )=max( numbers ( numbers ( : , 2 ) >0 ,1) ) ; %Max d i s t anc e157 end158 p l o t ( volumes , distV )159 t i t l e ( ' Var ia t ion in I n i t i a l Water Volume ' )

ASEN 2012 15 of 26 Fall 2017

Page 16: Project 2 - Bottle Rocket Model - WordPress.com · 2020. 1. 8. · ASEN 2012 Project 2 - Bottle Rocket Model Computational Project 8 Dec 2017 ID: 224 This report discusses the use

160 x l a b e l ( ' I n i t i a l Water Volume ' )161 y l a b e l ( ' Distance [m] ' )162163 %T i t l e164 s e t ( gcf , ' Pos i t i on ' , [ 1 00 100 1200 70 0 ] )165166167168169 %% Find a Parameter Set to get to 75 meters max height170 %Gonna j u s t do i t171 %I am going f o r the g l o ry . I want to h i t 75 m AND go as high as p o s s i b l e .172 %This w i l l a c t u a l l y be pre t ty easy . I j u s t choose the parameters f o r going173 %the f a r t h e s t d i s t anc e and then ad jus t the ang le u n t i l I get 75 meters .174 [ ˜ , p ] = max( distP ) ; %Gets index175 p = pres (p) ;176 [ ˜ , v ] = max( distV ) ; %Gets index177 v = volumes ( v ) ;178 [ ˜ , cd ] = max( distCD ) ; %Gets index179 cd = c o e f f s ( cd ) ;180181 %Redef ine X0 − the i n i t i a l he ight182 z0 =.25; %Height o f the t e s t stand [m]183184 opts = odeset ( 'MaxStep ' ,1 e−2) ; %Set the maximum step s i z e Just t r u s t me , i t

needs to be changed here . Don ' t comment t h i s out . : )185 thetaCalc1 = 1 . 2 7 3 0 ; %I n i t i a l ang le − 70 degree s − j u s t a guess186 range1 = 0 ; %To s t a r t − d i s t anc e ache ived187 t o l = . 0 1 ; %Tolerance188 tspan = [ 0 1 0 ] ;189 i t e r =0; %Number i t e r a t i o n s to avoid i n f i n i t e l oops190 whi l e abs ( range1−75) > t o l && i t e r <10191 i t e r=i t e r +1;192 [ ˜ , numbers , ˜ , ˜ , ˜ ] = RocketStuf f (p , cd , thetaCalc1 , v , tspan , opts , z0 ) ;193 range1 = max( numbers ( numbers ( : , 2 ) >0 ,1) ) ;194 i f range1 > 75+ t o l %Overshoot195 thetaCalc1 = thetaCalc1 + . 0 0 0 1 ;196 e l s e i f range1 < 75− t o l %Undershoot197 thetaCalc1 = thetaCalc1 − . 0 0 0 1 ;198 end199 end200201 cur rent=uitab ( parent , ' t i t l e ' , ' Target Distance Max Height ' ) ;202 [ t2 , numbers2 , t1 2 , t2 2 , tImp 2 ] = RocketStuf f (p , cd , thetaCalc1 , v , tspan , opts , z0 ) ;203 p lo tRocke tS tu f f ( t2 , numbers2 , t1 2 , t2 2 , tImp 2 , ' Target Distance Max Height ' ,

cu r r ent ) ;204 f p r i n t f ( ' Distance : %.2 f P: %f Theta : %f V: %f CD: %f \n ' ,

range1 , p , thetaCalc1 ∗180/ pi , v , cd )205206 %% Target Distance with minimum height acheived (hehe)207 %I am going f o r the g l o ry . I want to h i t 75 m with as l e a s t he ight as p o s s i b l e

.208 %This w i l l a c t u a l l y be pre t ty easy . I j u s t choose the parameters f o r going209 %the f a r t h e s t d i s t anc e and then ad jus t the ang le u n t i l I get 75 meters .210 thetaCalc2 = . 2 2 0 0 ; %I n i t i a l ang le − 8 degree s − j u s t a guess

ASEN 2012 16 of 26 Fall 2017

Page 17: Project 2 - Bottle Rocket Model - WordPress.com · 2020. 1. 8. · ASEN 2012 Project 2 - Bottle Rocket Model Computational Project 8 Dec 2017 ID: 224 This report discusses the use

211 range2 = 0 ; %To s t a r t − d i s t anc e ache ived212 tspan = [ 0 2 ] ;213 i t e r =0; %Number i t e r a t i o n s to avoid i n f i n i t e l oops214 whi l e abs ( range2−75) > t o l && i t e r <10215 i t e r=i t e r +1;216 [ ˜ , numbers , ˜ , ˜ , ˜ ] = RocketStuf f (p , cd , thetaCalc2 , v , tspan , opts , z0 ) ;217 range2 = max( numbers ( numbers ( : , 2 ) >0 ,1) ) ;218 i f range2 > 75+ t o l %Overshoot219 thetaCalc2 = thetaCalc2 − . 0 0 0 1 ;220 e l s e i f range2 < 75− t o l %Undershoot221 thetaCalc2 = thetaCalc2 + . 0 0 0 1 ;222 end223 end224225 cur rent=uitab ( parent , ' t i t l e ' , ' Target Distance Least Height ' ) ;226 [ t3 , numbers3 , t1 3 , t2 3 , tImp 3 ] = RocketStuf f (p , cd , thetaCalc2 , v , tspan , opts , z0 ) ;227 p lo tRocke tS tu f f ( t3 , numbers3 , t1 3 , t2 3 , tImp 3 , ' Target Distance Least Height ' ,

cu r r ent ) ;228 f p r i n t f ( ' Distance : %.2 f P: %f Theta : %f V: %f CD: %f \n ' ,

range2 , p , thetaCalc2 ∗180/ pi , v , cd )229230 %% For FUN let ' s launch this sucker as far as possible .231 %You know , get some range data f o r the Great Aerospace F a l l i n g Out Rocket232 %wars .233234 [ ˜ , th ] = max( distTh ) ; %Gets index235 th = ang l e s ( th ) ∗ pi /180 ; %Convert back to rad ians236237238 [ t2 , numbers2 , t1 2 , t2 2 , tImp 2 ] = RocketStuf f (p , cd , th , v , [ 0 7 ] , opts , z0 ) ;239 cur rent=uitab ( parent , ' t i t l e ' , 'Maximum Distance ' ) ;240 p lo tRocke tS tu f f ( t2 , numbers2 , t1 2 , t2 2 , tImp 2 , 'Maximum Distance ' , cu r r ent ) ;241242243244245246247248 %MMmmmm y e s s s s s , very n i c e . Looks l i k e the range o f t h i s rocke t can get up249 %to 143 meters with 54 meters in he ight . That ' s probably enough to c l e a r250 %the wa l l s o f Folsom i f someone were to bar r i cade themse lves i n s i d e . You251 %could a l s o s e t up on the br idge to the ITLL once the windows get bashed252 %out and hold down the bus ine s s f i e l d . Just accrue a few more aero k ids253 %with t h e i r rockets , boom you have a smal l mortar l i n e de fend ing the ITLL ,254 %the home o f our beloved wind tunne l . This range i s a l s o s u f f i c i e n t i f one255 %were to t ry to take the eng ine e r i ng towers . Note that the max he ight o f 54256 %meters , i f p laced j u s t so , w i l l a l low the top o f the tower to be launched257 %at with the maximum d i s t anc e away from the base in case o f re turn f i r e .258 %Al l very good th ings to know . . . .

ASEN 2012 17 of 26 Fall 2017

Page 18: Project 2 - Bottle Rocket Model - WordPress.com · 2020. 1. 8. · ASEN 2012 Project 2 - Bottle Rocket Model Computational Project 8 Dec 2017 ID: 224 This report discusses the use

Below are some helper functions.

1 func t i on dydt = makeThatRocketFlyBoys ( t , y )2 %makeThatRocketFlyBoys i s a system o f d i f f e r e n t i a l equat ions mode l l ing3 % s e v e r a l f l i g h t parameters o f a b o t t l e rocke t .4 %5 % Returns a column vecto r o f the d i f f e r e n t i a t e d parameters6 %7 % Format o f c a l l : makeThatRocketFlyBoys ( t , y )8 % where y i s a vec to r o f the same input parameters :9 % d i s t anc e

10 % he ight11 % v e l o c i t y h o r i z .12 % v e l o c i t y ve r t .13 % mass rocke t14 % volume o f a i r15 % mass a i r16 %17 %18 % Requires Global v a r i a b l e s : Mb in i t i a lA i rVo lume i n i t i a l A i r M a s s Pend Patm19 % Vb Cd At rhoAtm Ab R rhoW g CD Thrust l s20 % theta0 P0 Z0 X0 t C r i t i c a l t C r i t i c a l 2 tImpact ;21 % Assumes : a i r dens i ty constant , a c c e l e r a t i o n due to g rav i ty constant ,2223 %Created by ID 224 ( Almost put my name there , haha )24 %Created 11/24/1725 %ASEN 201226 %Pro j e c t 227 %P r o f e s s o r Anderson28 %Last Modif ied : 12/8/172930 %% General Info/setup31 %P r e a l l o c a t e32 dydt = ze ro s (7 , 1 ) ;33 %Requires Global v a r i a b l e s :34 g l o b a l in i t i a lA i rVo lume i n i t i a l A i r M a s s Pend Patm Vb Cd At rhoAtm Ab R...35 rhoW g CD l s theta0 P0 Z0 X0 t C r i t i c a l t C r i t i c a l 2 tImpact ;3637 %Get p r e s su r e i n s i d e the v e s s e l38 i f y (6 )<Vb && ( isnan ( t C r i t i c a l ) | | t<t C r i t i c a l ) %S t i l l water39 P = ( in i t i a lA i rVo lume /y (6) ) ˆ1 .4 ∗ P0 ;40 e l s e i f y (7 ) /y (6 ) > rhoAtm && ( isnan ( t C r i t i c a l 2 ) | | t<t C r i t i c a l 2 ) %S t i l l a i r

p ropu l s i on f o r the rocke t41 i f i snan ( t C r i t i c a l ) %The f i r s t time we are a i r−p r o p e l l e d − t h i s i s

t r a n s i t i o n time42 t C r i t i c a l = t ;43 end44 P = ( y (7 ) / i n i t i a l A i r M a s s ) ˆ1 .4 ∗ Pend ;45 e l s e %B a l l i s i t c phase46 i f i snan ( t C r i t i c a l 2 )47 t C r i t i c a l 2 = t ;48 %f p r i n t f ( 'P: %f CD: %f Angle : %f I n i t i a l Volume : %f \n ' , P0 ,CD,

theta0 ,Vb−i n i t i a lA i rVo lume )49 end50 P = Patm ;51 end

ASEN 2012 18 of 26 Fall 2017

Page 19: Project 2 - Bottle Rocket Model - WordPress.com · 2020. 1. 8. · ASEN 2012 Project 2 - Bottle Rocket Model Computational Project 8 Dec 2017 ID: 224 This report discusses the use

5253 %Ve loc i ty o f the Rocket54 V = s q r t ( y (3 )ˆ2+y (4) ˆ2) ;5556 %Need the heading o f the rocke t :57 h = atan ( y (4 ) /y (3 ) ) ;58 i f ( y (1 )−X0) ˆ2 + ( y (2 )−Z0) ˆ2 < l s ˆ2 %Bott l e s t i l l on f r i c t i o n l e s s launch rod59 h = theta0 ;60 end61 %Drag62 D = rhoAtm/2∗Vˆ2∗CD∗Ab;636465 %% Position66 %F i r s t parameter w i l l be he ight67 dydt (1 ) = r e a l ( y (3 ) ) ;6869 %We a l s o need h o r i z o n t a l d i s t anc e70 dydt (2 ) = r e a l ( y (4 ) ) ;717273 %% Thrust74 i f y (6 )< Vb && ( isnan ( t C r i t i c a l ) | | t<t C r i t i c a l ) %There i s s t i l l water l e f t75 F = 2∗Cd ∗ (P − Patm) ∗ At ;76 e l s e i f y (7 ) /y (6 ) > rhoAtm && ( isnan ( t C r i t i c a l 2 ) | | t<t C r i t i c a l 2 ) %Air p r o p e l l e d

now77 %C r i t c a l Pres sure ps ta r78 ps ta r = P ∗ ( 2 / 2 . 4 ) ˆ ( 1 . 4 / . 4 ) ;79 rho = y (7) /Vb;80 T = P/( rho∗R) ;81 i f p s ta r > Patm %Flow i s choked82 Te = ( 2 / 2 . 4 ) ∗T;83 Pe = pstar ;84 rhoE = Pe/(R∗Te) ;85 Ve = s q r t ( 1 . 4∗R∗Te) ;86 e l s e87 Me = s q r t ( ( 2 / . 4 ) ∗ ( (P/Patm) ˆ ( . 4 / 1 . 4 )−1) ) ;88 Te = T/(1+.2∗Meˆ2) ;89 Pe = Patm ;90 rhoE = Patm/(R∗Te) ;91 Ve = Me ∗ s q r t ( 1 . 4∗R∗Te) ;92 end93 dmairdt = −Cd∗rhoE∗At∗Ve ;94 F = abs ( dmairdt ) ∗Ve + (Pe−Patm) ∗At ;95 e l s e96 F = 0 ;97 end9899 %% Velocities

100 %Ve loc i ty h o r z i n t a l101 dydt (3 ) = r e a l (F∗ cos (h) /y (5 ) − D∗ cos (h) /y (5 ) ) ;102103 %Velocoty v e r t i c a l104 dydt (4 ) = r e a l (F∗ s i n (h) /y (5 ) − g − D∗ s i n (h) /y (5 ) ) ;105

ASEN 2012 19 of 26 Fall 2017

Page 20: Project 2 - Bottle Rocket Model - WordPress.com · 2020. 1. 8. · ASEN 2012 Project 2 - Bottle Rocket Model Computational Project 8 Dec 2017 ID: 224 This report discusses the use

106107 %% Mass of the Rocket108 i f y (6 ) < Vb && ( isnan ( t C r i t i c a l ) | | t<t C r i t i c a l )109 dydt (5 ) = r e a l (−Cd∗At∗ s q r t (2∗rhoW∗(P−Patm) ) ) ;110 e l s e i f y (7 ) /y (6 ) > rhoAtm && ( isnan ( t C r i t i c a l 2 ) | | t<t C r i t i c a l 2 )111 dydt (5 ) = r e a l ( dmairdt ) ;112 e l s e113 dydt (5 ) = 0 ;114 end115116117 %% Volume of Air118 i f y (6 ) < Vb && ( isnan ( t C r i t i c a l ) | | t<t C r i t i c a l )119 dydt (6 ) = r e a l (Cd∗At∗ s q r t (2/rhoW∗(P0 ∗ ( in i t i a lA i rVo lume /y (6) ) ˆ1 .4 − Patm)

) ) ;120 e l s e121 dydt (6 ) = 0 ;122 end123124125 %% Mass of the Air126 i f y (6 ) < Vb && ( isnan ( t C r i t i c a l ) | | t<t C r i t i c a l )127 dydt (7 ) = 0 ;128 e l s e i f y (7 ) /y (6 ) > rhoAtm && ( isnan ( t C r i t i c a l 2 ) | | t<t C r i t i c a l 2 )129 dydt (7 ) = r e a l ( dmairdt ) ;130 e l s e131 dydt (7 ) = 0 ;132 end133134135 %% Check i f rocket i s on the ground136 i f y (2 )<0137 i f i snan ( tImpact )138 tImpact = t ;139 end140 dydt = ze ro s (7 , 1 ) ;141 end142143 end

ASEN 2012 20 of 26 Fall 2017

Page 21: Project 2 - Bottle Rocket Model - WordPress.com · 2020. 1. 8. · ASEN 2012 Project 2 - Bottle Rocket Model Computational Project 8 Dec 2017 ID: 224 This report discusses the use

1 func t i on [ ] = p lo tRocke tS tu f f ( t , numbers , t1 , t2 , tImp , name , parent )2 %p lo tRocke tStu f f i s a func t i on merely to condense the p l o t t i n g o f the3 %v e r i f i c a t i o n case f o r p r o j e c t 2 in ASEN 2012 .4 %Format o f c a l l : p l o tRocke tS tu f f ( t , numbers , ˜ , t2 , tImp , name)5 %Returns nothing .6 %Assumes nothing . 3 :}78 %Created by ID 2249 %Created 12/2/17

10 %ASEN 201211 %Pro j e c t 212 %P r o f e s s o r Anderson13 %Last Modif ied : 12/2/17141516 %% Pull data apart17 x = numbers ( : , 1 ) ;18 z = numbers ( : , 2 ) ;19 vx = numbers ( : , 3 ) ;20 vz = numbers ( : , 4 ) ;21 mr = numbers ( : , 5 ) ;22 v = numbers ( : , 6 ) ;23 ma = numbers ( : , 7 ) ;24 thrus t = numbers ( : , 8 ) ;2526 %Some quick c o r r e c t i o n s f o r impact where v e l o c i t i e s change i n s t a n t l y27 %( d i s c o n t i n u o u s l y ) and thus cannot be i n t e g r a t e d − need to be manually s e t28 %a f t e r c o l l i s i o n with the ground again .29 inds = t>tImp ; %After impact30 x ( inds ) = max( x ) ;31 z ( inds ) = 0 ;32 vx ( inds ) =0;33 vz ( inds ) =0;3435 [ maxheight , idx ] = max( z ) ;36 peak = x ( idx ) ;37 maxdist = max( x ) ;3839 maxdist s = s p r i n t f ( 'Max Distance : %.2 f m ' , maxdist ) ;40 maxheight s = s p r i n t f ( 'Max Height : %.2 f m ' , maxheight ) ;4142 %% Save the Traajectory43 %Make an image and save i t44 f i g u r e (2 )45 p l o t (x , z )46 hold on47 p l o t ( [ 0 max( x ) +5] , [ 0 0 ] , 'k−− ' )48 text ( peak , . 9∗ maxheight , maxheight s , ' HorizontalAl ignment ' , ' cente r ' )49 text ( . 9 5∗ maxdist , . 0 5 ∗ maxheight , maxdist s , ' HorizontalAl ignment ' , ' r i g h t ' )50 t i t l e ( [ ' Trajec tory ' name ] )51 x l a b e l ( ' Hor i zonta l Distance [m] ' )52 y l a b e l ( ' V e r t i c a l Distance [m] ' )53 g r id on54 p r i n t ( [ ' Traj ' name ] , '−dpng ' )55 s e t ( gcf , ' Pos i t i on ' , [ 1 1 1400 9 00 ] )

ASEN 2012 21 of 26 Fall 2017

Page 22: Project 2 - Bottle Rocket Model - WordPress.com · 2020. 1. 8. · ASEN 2012 Project 2 - Bottle Rocket Model Computational Project 8 Dec 2017 ID: 224 This report discusses the use

56 c l o s e 25758 %% Subplot Verification Case59 tg = uitabgroup ( parent ) ;60 cur rent = uitab ( tg , ' t i t l e ' ,name) ;61 axes ( ' parent ' , cu r r ent ) ;6263 %f i g u r e64 subplot ( 2 , 3 , 1 )65 p l o t (x , z )66 hold on67 p l o t ( [ 0 max( x ) +5] , [ 0 0 ] , 'k−− ' )68 t i t l e ( ' Rocket Tra jec tory ' )69 x l a b e l ( ' Hor i zonta l Distance [m] ' )70 y l a b e l ( ' V e r t i c a l Distance [m] ' )71 g r id on7273 subplot ( 2 , 3 , 2 )74 p l o t ( t , th rus t )75 t i t l e ( ' Thrust ' )76 x l a b e l ( 'Time [ s ] ' )77 y l a b e l ( ' Thrust [N] ' )78 g r id on7980 subplot ( 2 , 3 , 3 )81 p l o t ( t , vx )82 t i t l e ( ' Hor i zonta l Ve loc i ty ' )83 y l a b e l ( ' Ve loc i ty [m/ s ] ' )84 x l a b e l ( 'Time [ s ] ' )85 g r id on8687 subplot ( 2 , 3 , 4 )88 p l o t ( t , vz )89 t i t l e ( ' V e r t i c a l Ve loc i ty ' )90 y l a b e l ( ' Ve loc i ty [m/ s ] ' )91 x l a b e l ( 'Time [ s ] ' )92 g r id on9394 subplot ( 2 , 3 , 5 )95 p l o t ( t , mr)96 hold on97 p l o t ( t ,ma)98 t i t l e ( 'Mass o f the Rocket and Air ' )99 legend ( ' Rocket ' , ' Air ' )

100 y l a b e l ( 'Mass [ kg ] ' )101 x l a b e l ( 'Time [ s ] ' )102 g r id on103104 subplot ( 2 , 3 , 6 )105 p l o t ( t , v )106 t i t l e ( 'Volume o f Air ' )107 y l a b e l ( 'Volume [mˆ3 ] ' )108 x l a b e l ( 'Time [ s ] ' )109 g r id on110

ASEN 2012 22 of 26 Fall 2017

Page 23: Project 2 - Bottle Rocket Model - WordPress.com · 2020. 1. 8. · ASEN 2012 Project 2 - Bottle Rocket Model Computational Project 8 Dec 2017 ID: 224 This report discusses the use

111112113 %% Standard Plots114 %Tra jec tory115 cur rent = uitab ( tg , ' t i t l e ' , [ ' Tra j e c to ry ' name ] ) ;116 axes ( ' parent ' , cu r r ent ) ;117 p l o t (x , z )118 hold on119 p l o t ( [ 0 max( x ) +5] , [ 0 0 ] , 'k−− ' )120 text ( peak , . 9∗ maxheight , maxheight s , ' HorizontalAl ignment ' , ' cente r ' )121 text ( . 9 5∗ maxdist , . 0 5 ∗ maxheight , maxdist s , ' HorizontalAl ignment ' , ' r i g h t ' )122 t i t l e ( ' Rocket Tra jec tory ' )123 x l a b e l ( ' Hor i zonta l Distance [m] ' )124 y l a b e l ( ' V e r t i c a l Distance [m] ' )125 g r id on126127 %Thrust128 cur rent = uitab ( tg , ' t i t l e ' , [ ' Thrust ' name ] ) ;129 axes ( ' parent ' , cu r r ent ) ;130 %f i g u r e131 inds=t<(t1 +.2) ;132 zoom = thrus t ( inds ) ;133 tzoom=t ( inds ) ;134 p l o t ( tzoom , zoom)135 hold on136 p l o t ( [ t1 t1 ] , [ 0 max(zoom) ] , 'b−− ' )137 text ( t1 , . 9 ∗ max(zoom) , ' \ l e f t a r r o w Phase 1 Ends ' )138 p l o t ( [ t2 t2 ] , [ 0 max(zoom) ] , 'b−− ' )139 text ( t2 , . 8 ∗ max(zoom) , ' \ l e f t a r r o w Phase 2 Ends ' )140 t i t l e ( ' Thrust ' )141 x l a b e l ( 'Time [ s ] ' )142 y l a b e l ( ' Thrust [N] ' )143 g r id on144145 end

ASEN 2012 23 of 26 Fall 2017

Page 24: Project 2 - Bottle Rocket Model - WordPress.com · 2020. 1. 8. · ASEN 2012 Project 2 - Bottle Rocket Model Computational Project 8 Dec 2017 ID: 224 This report discusses the use

1 func t i on [ t , y , tCr1 , tCr2 , tImp ] = RocketStu f f ( pres sure , coe f fDrag , theta ,volumeWater , tspan , opts , z0 )

2 %RocketStu f f i s a d i f f e r e n t i a l equat ion s o l v e r f o r the d i f f e r e n t t i a l3 %equat ions o f p r o j e c t 2 in ASEN 2012 . The equat ions are used to model the4 %f l i g h t o f a rocke t . See makeThatRocketFlyBoys f o r the e x p l i c i t5 %d i f f e r e n t i a l equat ions .6 %7 %Returns a t ( time ) vec to r and y matrix :8 % y ( : , 1 ) −> h o r i z o n t a l d i s t ance . . . . . . . . . . . . . . . . . [ m]9 % y ( : , 2 ) −> v e r t i c a l d i s t anc e . . . . . . . . . . . . . . . . . . . [ m]

10 % y ( : , 3 ) −> h o r i z o n t a l v e l o c i t y . . . . . . . . . . . . . . . [ m/ s ]11 % y ( : , 4 ) −> v e r t i c a l v e l o c i t y . . . . . . . . . . . . . . . . . [ m/ s ]12 % y ( : , 5 ) −> mass o f the rocke t as a whole . . . . . . [ kg ]13 % y ( : , 6 ) −> volume o f a i r in the rocke t . . . . . . . [ mˆ3 ]14 % y ( : , 7 ) −> mass o f the a i r in the rocke t . . . . . . [ kg ]15 % y ( : , 8 ) −> Thrust o f rocke t f o r each time . . . . . . [ N]16 %17 % Also r e tu rn s the t imes when the rocke t sw i t che s phases and impacts18 % ground .19 %20 %Format o f c a l l : RocketStu f f ( I n i t i a l a i r gage p r e s su r e in b o t t l e [ p s i ] ,

C o e f f i c i e n t21 % of drag , launch ang le [ rad ians ] ,22 % i n i t i a l volume o f water [mˆ 3 ] ,23 % [ s t a r t t i m e , end time ] , opt i ons f o r24 % ode45 ,25 % i n i t i a l Z he ight )2627 %Created by ID 22428 %Created 12/2/1729 %ASEN 201230 %Pro j e c t 231 %P r o f e s s o r Anderson32 %Last Modif ied : 12/8/173334 %% Set up the variables35 g l o b a l Mb in i t i a lA i rVo lume i n i t i a l A i r M a s s Pend Patm Vb Cd At rhoAtm Ab R...36 rhoW g CD l s theta0 P0 Z0 X0 t C r i t i c a l t C r i t i c a l 2 tImpact l o c k e r ;3738 g =9.81; %[m/ s ˆ2 ]39 rhoW = 1000 ; %Density o f water [ kg/mˆ3 ]40 Mb = . 1 5 ; %mass empty b o t t l e [ kg ]41 Vb = . 0 0 2 ; %volume o f the b o t t l e [mˆ3 ]42 Cd = . 8 ; %d i s cha rge c o e f f i c i e n t43 Patm = 1 2 . 1 ; %atmospher ic p r e s su r e [ p s i ]44 rhoAtm = . 9 6 1 ; %ambient a i r dens i ty [ kg/mˆ3 ]45 At = pi ∗ ( . 021/2 ) ˆ2 ; %area o f the throat [mˆ2 ]46 Ab = pi ∗ ( . 105/2 ) ˆ2 ; %cros s−s e c t i o n a l area o f the rocke t [mˆ2 ]47 R = 287 ; %Gas constant [ J /( kg∗K) ]48 Tatm = 300 ; %Air temperature [K]49 Ve loc i ty0 = 0 ; %i n i t i a l v e l o c i t y [m/ s ]50 X0 = 0 ; %i n i t i a l h o r i z o n t a l d i s t anc e [m]51 Z0 = z0 ; %i n i t i a l v e r t i c a l d i s t anc e [m]52 l s = . 5 ; %length o f the t e s t stand53 t C r i t i c a l = NaN; %Switch from phase 1 to 2

ASEN 2012 24 of 26 Fall 2017

Page 25: Project 2 - Bottle Rocket Model - WordPress.com · 2020. 1. 8. · ASEN 2012 Project 2 - Bottle Rocket Model Computational Project 8 Dec 2017 ID: 224 This report discusses the use

54 t C r i t i c a l 2 = NaN; %Switch from phase 2 to 355 tImpact = NaN; %Obvious5657 %Here are the v a r i a b l e s from the func t i on arguments58 P0 = pre s su r e ; % i n i t i a l gage p r e s su r e [ p s i ]59 theta0 = theta ; %i n i t i a l heading o f the rocke t60 CD = coe f fDrag ; %C o e f f i c i e n t o f drag => .3<Cd<.5 u s u a l l y61 v0 = volumeWater ; %i n i t i a l volume o f water [mˆ3 ]6263 %% Set Up64 P0 = (P0+Patm) ∗6894 . 76 ; %Now in Pa65 Patm = Patm∗6894 . 76 ; %Now in Pa66 in i t i a lA i rVo lume = Vb − v0 ; %[mˆ3 ]67 i n i t i a l A i r M a s s = P0∗ i n i t i a lA i rVo lume /(R∗Tatm) ; %[ kg ]68 Pend = P0∗( in i t i a lA i rVo lume /Vb) ˆ 1 . 4 ; %[ Pa ]69 M0 = Mb + rhoW∗(Vb − i n i t i a lA i rVo lume ) + (P0/(R∗Tatm) ) ∗ i n i t i a lA i rVo lume ; %[ kg ]70 In ishCondish = [ X0 ; Z0 ; Ve loc i ty0 ∗ cos ( theta0 ) ; Ve loc i ty0 ∗ s i n ( theta0 ) ;M0;

in i t i a lA i rVo lume ; i n i t i a l A i r M a s s ] ;717273 %% Solve the ODE7475 [ t , y ] = ode45 ( ' makeThatRocketFlyBoys ' , tspan , InishCondish , opts ) ;76 v = y ( : , 6 ) ;77 ma = y ( : , 7 ) ;787980 %% Share some additional info for each solved trajectory81 tCr1 = t C r i t i c a l ;82 tCr2 = t C r i t i c a l 2 ;83 tImp = tImpact ;848586 %% Thrust87 %Calcu la te Thrust88 Thrust=ze ro s ( l ength ( t ) , 1 ) ;89 f o r i = 1 : l ength ( t )9091 i f t ( i )<t C r i t i c a l %Water phase92 P = ( in i t i a lA i rVo lume /v ( i ) ) ˆ1 .4 ∗ P0 ;93 Thrust ( i ) = r e a l (2∗Cd ∗ (P − Patm) ∗ At) ;9495 e l s e i f t ( i )<t C r i t i c a l 2 %Air phase96 P = (ma( i ) / i n i t i a l A i r M a s s ) ˆ1 .4 ∗ Pend ;97 ps ta r = P ∗ ( 2 / 2 . 4 ) ˆ ( 1 . 4 / . 4 ) ;98 rho = ma( i ) /Vb;99 T = P/( rho∗R) ;

100 i f p s ta r > Patm %Flow i s choked101 Te = ( 2 / 2 . 4 ) ∗T;102 Pe = pstar ;103 rhoE = Pe/(R∗Te) ;104 Ve = s q r t ( 1 . 4∗R∗Te) ;105 e l s e106 Me = s q r t ( ( 2 / . 4 ) ∗ ( (P/Patm) ˆ ( . 4 / 1 . 4 )−1) ) ;107 Te = T ∗ (1+.2∗Meˆ2) ;

ASEN 2012 25 of 26 Fall 2017

Page 26: Project 2 - Bottle Rocket Model - WordPress.com · 2020. 1. 8. · ASEN 2012 Project 2 - Bottle Rocket Model Computational Project 8 Dec 2017 ID: 224 This report discusses the use

108 Pe = Patm ;109 rhoE = Patm/(R∗Te) ;110 Ve = Me ∗ s q r t ( 1 . 4∗R∗Te) ;111 end112 dmairdt = −Cd∗rhoE∗At∗Ve ;113 Thrust ( i ) = r e a l ( abs ( dmairdt ) ∗Ve + (Pe−Patm) ∗At) ;114115 e l s e %B a l l s i t i c Phase116 Thrust ( i ) = 0 ;117 end118 end119 y = [ y Thrust ] ; %Add thrus t to matrix o f rocke t parameters to be returned120121 end

ASEN 2012 26 of 26 Fall 2017