Question: 2. Throwing a ball Below are all the steps you need to follow, but you should also add your own meaningful comments to the code
2. Throwing a ball Below are all the steps you need to follow, but you should also add your own meaningful comments to the code as you write it 1 Start a new file in the MATLAB Editor and save it as CTask1p2.m 2) At the top of the file, define some constants (you can pick your own variablenames) i. Initial height of ball at release 1.5m ii. Gravitational acceleration 9.8 m/s i. Velocity of ball at release 4m/s iv. Angle of the velocity vector at time of release 45 degrees 3) Next, make a time vector that has 1000 linearly spaced values between 0 and 1, inclusive 4) If x is distance and y is height, the equations below describe their dependence on time and all the other parameters (initial height h, gravitational acceleration g, initial ball velocity , angle of velocity vector in degrees ). See the following illustration: Solve for x and y i. x(,)-VCOs(e--), we multiply by / 180 to convert degrees to radians. 180 180 5) Approximate when the ball hits the ground. i. Find the index when the height first becomes negative (use find). ii. The distance at which the ball hits the ground is value of x at that index ii. Display the words: The ball hits the ground at a distance of X meters. (where X is the distance you found in part ii above 6) Plot the ball's trajectory i. Open a new figure (use figure) ii Plot the ball's height on the y axis and the distance on the x axis (plot) iii. Label the axes meaningfully and give the figure a title (use xlabel, ylabel, and title) Hold on to the figure (use hold on) Plot the ground as a dashed black line. This should be a horizontal line going from 0 to the maximum value of x (use max). The height of this line should be 0. (see help plot for line colors and styles) iv v. 7) Run the script from the command window and verify that the ball indeed hits the ground around the distance you estimated in 5)i. You should get something like this
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
