Homework_2

.pdf

School

Rensselaer Polytechnic Institute *

*We aren’t endorsed by this school

Course

1100

Subject

Mathematics

Date

Feb 20, 2024

Type

pdf

Pages

6

Uploaded by LieutenantGrasshopper913

Report
Homework 2 This objectives of this problem are to give you experience creating and using MATLAB functions, using vectors, and solving a numerical problem in MATLAB. You will write a program that computes trajectories of a cannonball, on both Earth and Mars, using the equations of motion. Your main script will prompt for the ball's initial velocity angle (in degrees), speed (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 planet’s ground is level and the ball is traveling in a vacuum. For each trajectory, we will compute the coordinates of the ball at uniform time intervals, until the ball is on or in the ground. Theory Because we are computing the trajectory in a vacuum on a flat world, the equations of motion are very simple. Assume that the magnitude of the initial velocity is , the initial angle of the velocity vector is , and the initial height is . We can compute the initial components of the velocity vector as: Since there is no force acting on the horizontal direction, we know the horizontal component of the acceleration vector is: and hence the horizontal component of the velocity vector is constant: Thus the position at time is Derivation of the vertical vector components is similarly easy. Since the only vertical force is gravity, the vertical component of the acceleration vector is: where is the gravational constant ( m/s 2 on Earth, m/s 2 on Mars). Integrating over time, we find: We also find:
Finally, we can determine when the cannonball hits the ground by setting and solving for : Generally only the larger solution is physically sensible. Instructions In RPILMS, you will find the function trajectory_path. Download this function and put it in your MATLAB folder (or another folder you have put on the MATLAB path). You can learn how to use it with the help command. Do not change this function! First, you will write a script called homework2.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 trajectory_path to compute the trajectory coordinates and times for the cannonball, both for a shot on Earth and a shot on Mars. 3. Using the results from trajectory_path, print out the final time of each trajectory (which is when the cannonball hits the ground), both on Earth and and on Mars. 4. Plot each trajectory in the same figure. Put markers at the final location of the cannonball. (You might want to use the MarkerSize property to make this large enough.) The plot for a shot on Earth should be drawn in blue. Naturally, the plot for a trajectory on Mars should be in red. Make sure that you properly comment your script. In particular, we should be able to determine who the programmers are from your comments. Second, you must create the function point_on_trajectory. With the function I created, if I say "help point_on_trajectory", I get the following help text: POINT_ON_TRAJECTORY calculates the coordinates of a point on the trajectory at a specified time. A vector of times may be given, in which case vectors of x and y coordinates are returned. Parameters: t = time at which to compute the coordinates, or a vector of times g = gravitational constant y0 = initial height of trajectory v0x = the x component of the initial velocity v0y = the y component of the initial velocity Returns: x = the x coordinate of the position of the trajectory at time t. y = the y coordinate of the position of the trajectory at time t.
If t is a vector, then x(1), y(1) are the coordinates of the position at time t(1), etc. Your point_on_trajectory function should give the same help text. You will need to write it, using the equations of motion for a trajectory outlined above. The trajectory_path function calls point_on_trajectory as needed. You should not need to call point_on_trajectory directly! Finally, you must create the function impact_time, which computes the time when the cannonball should hit the ground. When I say "help impact_time" I see this help text: IMPACT_TIME calculates the time when the cannonball should land Parameters: g = gravitational constant to be used y0 = initial height v0y = y component of the initial velocity Returns: t = time the projectile hits the ground This function will also be called by trajectory_path as needed; you should not call it yourself, not even from your homework2.m script. Use the appropriate equation from above to solve this part of the problem. Hint: Since there are two solutions, you will need the max function to choose the larger one. One team member must upload to RPILMS, as attachments , your homework2.m script, your point_on_trajectory and impact_time functions, and any other functions you might create to solve this problem. In the RPILMS “submit” box, each team member should list the names of the other team members, so we can be sure that the entire team receives the same grade for the assignment. 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. Functions should provide suitable "help" text. You do not need to turn in the trajectory_path function, since that was given to you. 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. Develop the impact_time function and verify that it works. See the sample output below. 2. Develop the part of point_on_trajectory function and verify that it works. See the sample output below. 3. Develop the part of homework2.m that gets the initial conditions and calls trajectory_path. 4. Develop the part of homework2.m that computes and prints the times at impact, using the values returned from trajectory_path. 5. Plot the results. 6. Review your code and the grading check list.
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