The goal of this lab is to write a MATLAB function that calculates the height (and possibly velocity, acceleration, rocket internal pressure, mass, etc.) for a given set of parameters (nozzle diameter, initial internal pressure, water volume, etc.) and initial values. Your assignment is to email me (dlivelyb@uoregon.edu) your funciton, and the Matlab script that calls it, giving it real numbers for the initial conditions, etc. I also request a graph of height vs. time for a given simulation.
See the MATLAB Information page for details.
Labs 1 and 2 combine to provide experiences in scientific programming to simulate data expected from a water rocket launch (Lab 1), and some hands-one experience launching simple water rockets under various initial conditions (starting water volume, pressure, etc.) (Lab 2). For this latter part you will be challenged to figure out a way to obtain real data for a launch, and then you will compare that to your simulation.
Your principle task for Lab 1 is to code a Matlab function that will provide simulated
data for a particular water rocket launch. Doing this will entail learning some specific
programming elements of Matlab. These will be found in Pratap, Chapters 2 & 3.
Here are some things to think about:
The process of writing a simulation is two-fold:
PART 1) DOING PHYSICS: On one hand, there is the physics to be done, entailing figuring out how thrust, impulse, momentum transfer and conservation, fluid drag, etc. all come together to a correct set of governing equations that reliably give one the height, say of the rocket as a function of time.
This part of the problem also involves setting out the initial conditions, such as how much water is in the rocket, how much pressure has been applied, etc. An American Journal of Physics paper by Finney (2000) is a great starting point, as it presents one way of finding "thrust, drag and mass of a rocket as a function of time in order to find acceleration, velocity, and position (particularly, height).Looking at Finney (2000), how is the initial equation, (1), useful? (hint, what are its units). How will characterizing thrust, T, be helpful in simulating the flight of a water rocket?
Note that Finney moves from there to consideration of Bernoulli's equation in order to characterize pressure (P) in the rocket. This provides for relating the rocket internal pressure to water velocity just outside the nozzle, v_e, which is also in the equation for thrust, and thus an expression for thrust in terms of internal pressure (P), outside pressure (P_a), and the area of the nozzle. This suggests that the area of the nozzle could be another variable controlling the flight of a water rocket.
Note the simplifying assumptions regarding use of Bernoulli's equation, do you understand why they might be made?
As Finney notes (and as one might intuit), the thrust depends on finding the pressure inside the rocket as a function of time. At this point in analyzing the physics of the problem, this suggests that a simulation might be built around calculating (tracking) the pressure inside the rocket as time steps forward in small increments.
To move forward, Finney assumes the ideal gas law applies to the air inside the rocket (and what remains inside is water of course), and that we assume the air expands isothermally (what does that mean?). Thus equation 5 is arrived at, and one can take the derivative of pressure with respect to time (6) and thus 'step' through pressure inside the rocket during our simulation. Some substitutions lead to (7), the derivative of pressure again, but a complicated expression. In looking at (7), ask yourself what would make for larger, initial time-step changes in pressure.
For purposes of this lab, we won't pursue an analytical solution such as (8). Instead, we will proceed to forming up a numerical solution that can be programmed in Matlab. However, we do need to consider section B, Drag, in order to work out the dynamics and kinematics of the rocket's flight.
Looking at equation (9) for drag (F_d), do you think you could come up with this equation with a little thinking? I would likely posit that the density of the air or liquid that the rocket is moving through (rho) would be in there, also, the cross-sectional area (A). I wouldn't know to use a 'coefficient of drag' (C_d) and, though I would expect more drag as the velocity of the rocket increases, I wouldn't know to relate it to *the square of* velocity. Realize, of course, that F_d is a better approximation to reality within certain velocity ranges, as noted in the text.
For now we won't worry a lot about D, other than coming up with a reasonable estimation of it later for moving forward with our simulation. Skipping ahead to III Numerical Solution, it's worth thinking about (16) and (17). That's where we transition from thinking about just physics to considering how to numerically solve these equations, which is discussed next.
2) SCIENTIFIC COMPUTING TO SIMULATE PHYSIC EXPERIMENTS:: The other part of the problem is coding a Matlab simulation that solve the governing equations. Ideally this simulation is a Matlab 'function' such that one can pass it various values for initial water volume, pressure, etc., and it will pass back, say, simulated position vs. time data for graphing and comparison to real experiments.
Looking at equations (16) and (17), note first the format of each equation in (16) (and convince yourself you understand where the pressure equation comes from....). This suggests what is known as an 'iterative solution,' where we calculate the initial values for variables (P, v, y), divide the time of flight of the rocket into small, equal steps (in time), then step through a programmatic loop and calculate the next iterations values for P, v and y until it makes sense to quit. Before we launch into coding, however, convince yourself that:
(16b) makes sense to you. Where does this equation come from?
(16c) makes sense to you. Where does this equation come from?
you understand how (17) was constructed. What is the underlying, fundamental physics equation that is used to derive (17)?Now let's think about how to construct a Matlab *function* that will do our bidding, i.e. calculate successive (or iterative) values for P, v, and y, for a given time step (dt) and for initial values for rocket air pressure, volume of water, etc.
ARITHMETIC AND ARRAYS: First, you should familiarize yourself with how arithmetic operations are performed and how *variables* (scalar, vector and matrix arrays) work in Matlab. To do so, consult Chapter 2 of Pratap (Lessons 1 & 2).
FUNCTIONS: Lesson 5 of Pratap Chapter 2 gives background on making a Matlab function. The general idea is that you pass numbers (variables such as initial pressure, volume of water, mass of empty rocket, area of nozzle, etc. in this instance) to the function, and it passes back the results of the simulation, usually as arrays (of time, height, velocity, etc. in this case).
SETTING CONSTANTS: It's typical to set some constants (e.g., a value for 'g' as -9.8 [m/s/s]) within the function. These are things that won't change from one call of the function to the next.
SET INITIAL VALUES: You might need to do some simple arithmetic with passed variables to set up the initial value for drag (D), for example. Typically one also *initializes* the first values of simulated data arrays (time, height, etc.) within the function.
FOR OR WHILE LOOPS: This is the critical part of the function (simulation), where you step through (iterate) time and calculate the next values of various working parameters (pressure, mass, acceleration, velocity position) from the previous (steps) values. The general form of a FOR loop is:
t(1) = 0;
dt = 0.1;
P(1) = P0 % this is the initial air pressure in rocket, passed to functionfor i=2:1000
t(i) = t(i-1) + dt;
P(i) = Pn - ( Pn^2 / (P0*V0) ) * Ae * sqrt(2*(Pn-Pa)/rho_w)*dt;
% and yet more math calculating next values for mass, acceleration, velocity, etc.end
In this case, the for will loop 999 times, with i starting at 2, then 3, etc. until it reaches 1000. After 1000, the loop completes.
A WHILE loop exits when a condition is met. For example:
t(1) = 0;
dt = 0.1;
P(1) = P0 % this is the initial air pressure in rocket, passed to function
Pd = 1;
i = 2;
while (Pd > 0)
t(i) = t(i-1) + dt;
P(i) = Pn - ( Pn^2 / (P0*V0) ) * Ae * sqrt(2*(Pn-Pa)/rho_w)*dt;
Pd = P(i) - Pa;
i = i + 1;end
In this case, the while loop continues until the difference in pressure (Pd) between inside the rocket and outside
(which is Pa, or atmospheric pressure) reaches zero. Once Pd reaches zero, the while loop completes.PASSING SIMULATED DATA BACK: Once your function has completed its calculation, you pass it back to the 'calling' routine (or the Matlab command line). This is all taken care of in the top line of the function, which could look like:
function [t,y,v,a,P,ymax] = my_spiffy_rocket_simulator(nzd, C, dt, P0, y0, v0, V0, mr, VT)
The last line of the function is typically look like:
return
In this example, I've passed parameters (variables) and initial values within the '()'s on the RHS of the function call
The Matlab expressions (which I calculate in the function) between the '[]'s are passed back to the calling routine.
FOR THIS LAB: your challenge is to write a working Matlab function that will calculate water rocket height vs. time, given initial values and parameters.å
It probably doesn't make too much sense to work with a partner for this lab, although it is fine to discuss problems with other students or your TA. Each student needs to turn in their own notebook and code. For future labs, collecting data with a partner will be encouraged, but most of the data analysis will again be done individually.