In: Computer Science
MATLAB
Write a script which asks the user of the program to provide an initial horizontal position, initial vertical position, initial velocity, and angle. Create a time vector spanning from zero seconds to 100 seconds incremented at 0.01 seconds. Call the function that you created in the previous problem to calculate the trajectory and velocities of the projectile. Find the maximum height of the projectile and the time at which it reaches that point. Write a neat sentence stating what the maximum height of the projectile is as well as the time at which that point was reached.
Code:
syms X G U theta
x=input('Enter initial horizontal position: ');
y=input('Enter initial vertical position: ');
th=input('Enter angle of projection in degrees: ');
v=input('Enter velocity of projection: ');
g=9.81;
t=0:0.01:100;
Vx = v.*cosd(th);
Vy = v.*sind(th)-g.*t;
velocity_at_t = sqrt(Vx.^2 + Vy.^2)
trajectory = X*tan(theta) - G*X^2/(2*U.^2.*cos(theta).^2)
maximum_height=(v.^2.*sind(th).^2)./(2.*g);
time = (2*v.*sind(th))./g;
fprintf('The maximum_height of the projectile is: %.2f at %.2f seconds',maximum_height,time)
(Feel free to throw an upvote or ask below in the comments if you have any doubts)