Homework_3

pdf

School

Rensselaer Polytechnic Institute *

*We aren’t endorsed by this school

Course

1100

Subject

Mathematics

Date

Feb 20, 2024

Type

pdf

Pages

9

Uploaded by LieutenantGrasshopper913

Report
Homework 3 This objectives of this problem are to give you further experience creating MATLAB functions, using iteration, and solving numerical problems in MATLAB. You will write a program that computes the trajectory of a ball, using Euler's method to approximately solve the differential equations of motion. Your main script will prompt for the ball's initial angle (in degrees), velocity (in meters per second), an initial height above the ground (in meters), and a time interval between each coordinate pair (in seconds). For this simulation, we will assume the ground is level. You will compute the coordinates of the ball at uniform time intervals, until the ball is on or in the ground. You will perform these calculations and plots for trajectories on both Earth and Mars. Some code will be given, to help you get started. Theory Euler's method is a numeric method to approximately solve differential equations; you probably learned it in calculus class. Basically, if then Clearly this becomes increasingly correct as , since this is the very definition of the derivative . Euler's method can be used to work out the trajectory of a cannon ball, letting us make our model more realistic (such as including wind drag). To use Euler's method, we assume that the velocity at time remains constant for a time step . Then a new velocity is computed computed for time : Of course, we will also need initial conditions at time for , , , and , which come from the initial position and velocity of that cannon ball. The accelerations at time step come from considering both gravitational acceleration and drag forces. The drag equation is: Here, F d is the magnitude of a vector whose direction is opposite the velocity vector. To calculate the actual trajectory, we will need add together all the forces, and ultimately calculate the acceleration. We will need to know:
The density of air, kg/m 3 on Earth — the actual value depends on altitude and temperature The coefficient of drag on a sphere: The cross-sectional area of the projectile ball, A The mass of the projectile, m We can break the forces into components. The only horizontal force is going to be the x- component of the drag: where is the magnitude of the velocity, or speed, of the projectile. For the vertical forces, we have both the y-component of the drag, and gravitational acceleration: where g is the gravitational constant (-9.81 on Earth, -3.73 on Mars). Calculating accelerations and simplifying, we get Let's combine some of these factors, to define and choose a reasonable value for . For example, if we had a 1 kg iron projectile, it would have a diameter of approximately 6.5 cm, and we would have . More interesting simulations result with a smaller value of , which might be the case for a more massive projectile. So we will use for our experiments, and a function atmosphere_density to compute , and we have the differential equations: The atmosphere_density function has some additional parameters that relate to the different compositions, temperatures, and quantities of the atmospheres of Earth and Mars. The values are all given in the help text for atmosphere_density . Since the functions that compute trajectories will ultimately call atmosphere_density , these functions also will have these additional atmospheric property parameters.
Instructions In RPILMS, you will find the functions drag_trajectory_state , drag_trajectory_acceleration , and atmosphere_density . Download these functions and put them in your MATLAB folder (or another folder you have put on the MATLAB path). You can learn how to use these functions with the help command. Do not change either drag_trajectory_state or atmosphere_density ! You will need to modify drag_trajectory_acceleration later, if you want full credit for this homework. First, you need to write the function drag_trajectory_path . With the function I created, if I say " help drag_trajectory_path ", I get the following help text: DRAG_TRAJECTORY_PATH computes the coordinates and times of a trajectory. Parameters: V0 = Magnitude of the initial velocity vector, i.e., speed. ANG = Angle from horizontal of initial velocity vector. P0 = Ground standard pressure (Earth: 101325, Mars: 600Pa) T0 = Ground temperature (Earth: 288.15K, Mars: 210K) L = Temperature lapse rate (Earth: 0.0065, Mars: 0.0025 K/m) M = Molar mass (Earth: 0.0289644, Mars: 0.04334 kg/mol) G = Gravitational constant (Earth: 9.81, Mars: 3.73) Y0 = Initial height of the cannon ball. DT = Time step to use Returns: X = X-coordinates of trajectory at time step. Y = Y-coordinates of trajectory at time step. T = list of time steps. At time T(1), the coordinates are ( X(1),Y(1) ). At time T(2), the coordinates are ( X(2),Y(2) ). And so forth. Your function should accept the same arguments, in the same order, and return the same results, in the same order. (Note that this needs the atmospheric properties to be supplied for the planet on which you want to compute the trajectory.) Your drag_trajectory_path will need to build up the result vectors X , Y , and T . It first must compute the initial values of the state variables. Then it must repeatedly call drag_trajectory_state to compute new values for the state variables. The drag_trajectory_state function uses Euler's method to compute new position coordinates, new time, and new velocity components from the current position, time, and velocity (using drag_trajectory_acceleration to compute the acceleration components, given the cannon ball's current velocity and height). The new values associated with time and position must be appended to the end of X , Y , and T . Keep collecting state variables until the cannon ball is on the ground (or has just sunk into the ground).
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Second, you must write the script, homework3.m , that does these things: 1. Prompts for and gets the initial angle, speed, and height of the cannonball, as well as a time step to use for plotting. 2. Uses drag_trajectory_path to compute trajectory coordinates and times for both Earth and Mars. 3. Using the results of drag_trajectory_path , print out the final time in the trajectory (which is when the cannonball hits the ground), for both Earth and Mars. 4. Plot the trajectories. Put a marker at the final location of the cannonball. Draw the trajectory and marker for the Earth shot in blue, and for the Mars shot in red. (You might want to use the MarkerSize property to make this large enough.) Make sure that you properly comment your script. In particular, we should be able to determine who the programmers are from your comments. Probably you realize that you can easily copy and edit your homework2.m script to create your homework3.m script. You will need to change the function calls to call the new functions and pass arguments for the atmospheric properties for each planet, but that is straightforward. Finally, you will need to modify the drag_trajectory_acceleration script to properly compute the acceleration, using the drag equations. You will need to call atmosphere_density to compute at the current height of the cannon ball. You must turn in your homework3.m script, your drag_trajectory_path function, your modified drag_trajectory_acceleration function, and any other functions you might create to solve this problem. Be sure your work is well commented! In particular, don't forget the heading comments in your main script indicating who the programmers are, etc. Upload these files to RPILMS as attachments. How to do this I suggest you go about this assignment in stages. Develop part of your algorithm, turn it into Matlab code, and test it. You might want to do it something like this: 1. Modify your homework2.m script to create your homework3.m script, calling drag_trajectory_path . 2. Create your drag_trajectory_path function. You will need to use iteration in this function. You will need to build vectors of results, one element at a time. (All of this is covered in the Lecture 3 notes.) Do not worry about the drag calculations at this time. Example output is shown below. 3. Modify the drag_trajectory_acceleration function to account for drag. You will find sample output below. 4. Make sure you have put in proper comments in your functions (remembering to change comments in drag_trajectory_acceleration , and homework3.m if you copied it from homework2.m ). Make sure that help drag_trajectory_path tells how to use your function. 5. Review your code and the grading check list.
Sample Output Suppose you follow the advise above, and have completed step 2. At this point, you have not added drag forces to the computation; essentially the cannon ball is travelling in a vacuum. If you were to run homework3.m at this point, you might see this output: Please enter the initial speed of the ball (m/s):1000 Please enter the initial height of the ball (m):7 Please enter the angle of velocity from the horizontal (degrees):49 Please enter the time step (seconds):0.01 Final time for Earth shot is: 153.8900 Final time for Mars shot is: 404.6900 >> The plot you get should look like this:
Getting the correct results in a vacuum is a major milestone! Adding the drag equations is pretty simple. One you have modified trajectory_acceleration , running homework3.m might produce output like this: Please enter the initial speed of the ball (m/s):1000 Please enter the initial height of the ball (m):7 Please enter the angle of velocity from the horizontal (degrees):49 Please enter the time step (seconds):0.01 Final time for Earth shot is: 81.7000 Final time for Mars shot is: 396.2800 >>
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
This would create a plot like this: If you were to magnify the lower left portion to see the trajectory on earth more closely, you should see how air drag has affected the curve so it is no longer a parabola:
Other Notes We probably will be using and modifying the drag_trajectory_path function in another homework problem, so it is important that you follow the specification shown here. You will want to keep it for future assignments. As for your script, you may embellish it as you please, as long as the result is basically what is specified here. Please do not animate output, but feel free to add legends to the axes, draw a cannon to launch the ball, a "splat" where it hits the ground, etc. But none of this is required. Grading This assignment will be graded out of 100 points, assigned as follows: Properly commented: 10
There is a proper drag_trajectory_path function, with the proper parameters and return values: 10 points for the correct name, 10 points for the correct return values in the correct order, 10 points for the correct parameters in the correct order • The drag_trajectory_path function uses Euler's method and drag_trajectory_state : 15 points • The drag_trajectory_path function computes correct results (either in vacuum or with drag): 10 points for t , 10 points for positions, 10 points for properly using the drag equations in drag_trajectory_acceleration . These results are all Matlab vectors. The trajectories are plotted: 10 points The final time is correctly computed: 5 points
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help