Page 1 of 1

Objectives Completing this project will solidify your understanding of loop statement (while loop), plotting, numerical

Posted: Fri May 06, 2022 7:14 am
by answerhappygod
Objectives Completing This Project Will Solidify Your Understanding Of Loop Statement While Loop Plotting Numerical 1
Objectives Completing This Project Will Solidify Your Understanding Of Loop Statement While Loop Plotting Numerical 1 (279.52 KiB) Viewed 40 times
Objectives Completing this project will solidify your understanding of loop statement (while loop), plotting, numerical calculations and user-defined functions. In addition, you will learn how to analyze a problem using MATLAB as a TOOL. You cannot use break for the entire project. Project Introduction Ejection Part (a) A model rocket is propelled upwards by an engine and falls back to earth under a parachute. Local rocketry clubs host contests to see who can keep their rocket in the air the longest. Performing well in these contests requires carefully choosing an engine from the products available. Let's write a simulator to help us make that choice. Descent Boost A rocket's flight can be broken up into three parts: the boost phase (when the engine is firing), the coast phase (after the engine has burned out), and the descent phase (after the parachute has been ejected). During the boost phase, two forces are acting on the rocket: thrust from the engine and gravity. During the coast, gravity is the only relevant force. During descent, we'll assume that the rocket falls with a constant terminal velocity. Solving the physics equations is easier if we work with very short time intervals; therefore, we'll break up the rocket's flight into brief periods of time each dt seconds long. Let dt = 0.1 s. During each interval, we'll update various properties of the rocket, such as its height and velocity. Assume that height, velocity, and time all start at 0. When the engine is firing, we'll also track the impulse produced by the engine; this starts at 0 too. For this simulation, assume that the acceleration due to gravity is g = 9.8m/s², that the rocket has a mass of m = 0.15 kg, and that the rocket's terminal velocity under parachutes is vr= - 4.5m/s. Coast
Rocket engines are labeled with their total impulse (force of the engine times how long it fires for), thrust (aka force), and delay (time between thrust cutoff and parachute ejection). This project we'll consider a "B6-4" engine, which provides 5 N-s of total impulse (the "B"), 6 N of average thrust, and has a 4 s delay. 1.1 Boost phase During boost, the total force acting on the rocket is F = T-mg, where T is the average thrust of the engine. Newton's law says that force is related to acceleration, a, by F = ma. You can combine these equations to solve for a. For each time interval, update the rocket's state via the following procedure: 1. Increment height: dt times the current velocity 2. Increment velocity: dt times the current acceleration 3. Increment accumulated impulse: dt times the current thrust Additionally, plot a red circle at the coordinates (t, h) after each update (where t is time and his height). Use hold on so that these circles build up a plot of the rocket's trajectory over time. The boost phase ends when the accumulated impulse surpasses the total impulse of the engine. Save the time for boost phase in a variable: t_boost. 1.2 Coast phase During coast, the total force acting on the rocket is F=- mg. Update the rocket's height and velocity using the same procedure as above, but plot blue circles instead. The coast phase ends whene the engine's delay has elapsed or the rocket has crashed into the ground (h is no longer positive). If the rocket crashes, display the message "Lawn dart!". 1.3 Descent phase During descent, the rocket's velocity is fixed at vr. Continue to update its height during each time interval using the relevant steps in the procedure above, and plot a magenta circle after each update. The descent phase ends when the rocket reaches the ground (h is no longer positive). 1.4 Report Print a message indicating how long the rocket was in the air for (don't forget units!). Label the axes of your plot (don't forget units there either). Start by listing out all your variables: constants of the problem, states of the simulation, etc. Collect both the information you know and the quantities you're going to need, and give everything a name. Then add comments to show how you'll break down the task. Finally, fill in the math one section at a time, plotting your results and looking at the Workspace to check your work. Save your script file under name rocketB6_4.m. We'll be using this code again in next part, so be kind to yourself and your group partner by adding helpful comments, choosing meaningful variable names, etc. Note: Some of you may know how to solve this problem by hand, without performing a discrete time simulation like this. That's a great way to check your work! But for this project, the task is to implement the simulation. (You will be glad you did when it comes later in future.)
Part (b) In Part (a) you simulated the flight of a model rocket powered by a B6-4 engine and computed how long it stayed in the air for. We may be able to do better with a different choice of engine, though. The rules of our "airborne duration" contest say that we must use a “B” engine (fixing the total impulse), but we can buy products with different average thrusts and ejection delays. In this project, we'll perform a sensitivity analysis to see how big an impact these parameters have on our rocket's performance.
2.1 Encapsulate simulation as a function Currently, our simulation is written as a Matlab script that prints the time aloft to the command window. It would be more convenient if the simulation were a user-defined function that took engine parameters as inputs and returned the time aloft as its output; then we could easily vary the inputs and collect the results for further analysis (without having to copy-paste). Implement the following function: function timeAloft = rocketTime (totalImpulse, avgThrust, ejectionDelay, dt) & Compute how long a model rocket stays aloft when powered by a & specific engine. 응 % totalImpulse is the total impulse of the engine [N*s], avgThrust is the average thrust of the engine [N], and ejectionDelay is the % delay between thrust cutoff and parachute deployment [s]. timeAloft indicates how long the rocket was in the air [s] after this engine was ignited. & &dt is the timestep. 8 % Non-engine parameters of the model are hard-coded to the following & values: mass = 0.15 kg, g = 9.8 m/s^2, vt = -4.5 m/s. Copy the function header and the entire function comment given above into your file rocketTime.m. Recall that the function comment is the specification and must be complete. Your code from Part (a) will form the basis of this function, but be sure to remove any extraneous features that are not necessary to meet this function's specification (e.g. printed output, plots, etc.). Test your new function in the command window by providing it with the parameters of the B6-4 engine from Part (a); it should return 14.4 s. Something we haven't mentioned yet is the timestep dt, which was set to 0.1 s in Part (a). This controls the speed and accuracy of the simulation. The accuracy is affected in two ways: during a single phase of flight, we approximate the physics equations-of-motion by treating velocity as constant over each timestep; by making dt smaller, we more closely represent the true, smooth behavior. Additionally, dt affects how precisely we detect the transition between phases of flight; a smaller dt allows us to transition from boost to coast closer to when the engine would actually cut off. Of course, a smaller dt also means more loop iterations and therefore a slower simulation. Write a script, analyzeRockettimestep.m, that calls the function above and plots the rocket's flight duration vs. time step for dt from 0.005 s to 0.1 s with increment of 0.005 s, using B6-4 engine (5 N-s of total impulse (the "B"), 6 N of average thrust, and 4 s delay). Title the plot "Sensitivity to time step" and label the x and y axes
appropriately (with units, as always). Write a comment in your script saying how time step affects your simulation results. This is our first sensitivity analysis, showing that our results are very sensitive (changing by several seconds) to a parameter that's not even physical! Understanding the uncertainty in your results is critical in science and engineering. 2.2 Analyze effects of ejection delay (bonus part) By changing the ejection delay of the engine, we control how high the rocket is when it deploys parachutes: deploy too early, and the rocket won't have reached its peak altitude yet; deploy too late, and the rocket might become a lawn dart! We'd like to visualize our sensitivity to this delay. Implement the following function (it should call your function rocketTime, and yes, you can call a function within a function as long as they are under the same folder, or you provide the working directory before calling): function [delays, times] = delaySensitivity (avgThrust, maxDelay) Compute rocket flight times for a range of ejection delays. Engine is assumed to be B-class (5 N*s total impulse) with an % average thrust of avgThrust [N]. % delays is a vector of ejection delays [s], running from 0 s to % maxDelay [s] in increments of 0.25 s. times is a vector of rocket flight times, such that times (k) is how long the rocket was in the air when powered by an engine with an ejection delay of delays (k). Write a script, analyzeRocket.m, that calls this function and plots the rocket's flight duration vs. delay time for delays as large as 7 s, using B6 engines (6 N average thrust). Set the time step for this section to be 0.001 s. Title the plot "Sensitivity to ejection delay" and label the x and y axes appropriately (with units, as always). Write a comment in your script saying which delay you would choose to win the "airborne duration" contest.