In: Computer Science
MATLAB
Write a code that takes the initial velocity and angle as an input and outputs the maximum height of the projectile and its air time.
Follow the pseudo code below. This will not be provided in as much detail in the future so you’ll have to provide pseudocode or a flowchart to showcase your logic. For this first assignment though, the logic is laid out below with some indented more detailed instructions.
PROGRAM Trajectory:
Establish the User Interface (Typically referred to as the UI);
INPUT INPUT
Solve Solve Print
Start with an explanation of activity
Ask the user for the initial velocity;
Ask the user for the initial angle;
Include descriptive requests for inputs so the user knows what information is required.
for the maximum height the ball reaches;
for the length of time the ball is in the air;
the answers for the user;
Include a description with that return so the user understands what the data is
Plot height versus time; Plot height versus distance;
Do not overwrite your previous figure! This is a new plot but you still want the old one.
Make it clear what the plots are. Label the plot axes with units, include a title, and use a marker for the plot points.
END
program:
velocity = input("Please enter user initial velocity: ");
angle = input("Please enter initial angle in degrees: ");
angle = angle*pi/180;
%convert angle in degree to radian
gravity = 9.80;
max_height = velocity^2 * sin(angle)^2 / (2*gravity);
%formula to find max_height
time_of_flight = 2*velocity*sin(angle)/gravity;
%formula to find lenght time
fprintf("maximum height the ball reaches: %d\n",max_height);
fprintf("length of time the ball is in the air:
%d\n",time_of_flight);
t = 0:time_of_flight;
height = velocity.* t.*sin(angle)./4;
dist = velocity.*t;
g = f.*sin(10*t);
subplot(3,1,1);
plot(t,height);
xlabel('time');
ylabel('height');
title('time vs height');
subplot(3,1,3);
plot(dist,height);
xlabel('distance');
ylabel('height');
title('distance vs height');
Output: