Assuming negligible air resistance, for the gravitational constant (g) (take g=
ID: 3603093 • Letter: A
Question
Assuming negligible air resistance, for the gravitational constant (g) (take g= 9.81 m/s), an initial velocity (Vo) in [m/s], and an angle of departure (0) in [deg] (here, let's assume 0 0-90), the position of the projectile launched from the origin (xo.yol -I0,0]) is given as follows: x = Vo cos(0)t y = Vo sin(0)t--gt2 Utilizing modular programming, complete the following tasks: a) (5 pts) Write a user-defined MATLAB function named projectile inputs, which prompts and checks the user inputs of the initial velocity (Vo) in [m/s], angle of departure (0) in [deg], and the instantaneous time (t) in [s]. Please remember to check all applicable conditions for the user inputs. b) (12 pts) Write a user-defined MATLAB function named projectile motion, which calculates and outputs o o o o the total flight time (to) the total horizontal traveled distance (also known as the range (R)) the maximum height (H) the instantaneous position (lx,y]) of the projectile at a given time (t) from the user input. c) (10 pts) Write a user-defined MATLAB function named projectile_ trajectory, which plots together the trajectory of the projectile from the time it is launched to the time it lands on the ground (assuming the projectile cannot penetrate the surface of the earth) the instantaneous position ([x,y]) of the projectile at a given time (t) from the user input. o o Please remember to label the axes, add legends, and title your plot. d) (3 pt) In your main script, call three functions to study the projectile motion. Hint: Here is a useful resource for information regarding projectile motion: http:/hyperphysics.phy-astr.gsu.edu/hbase/traj.html:bExplanation / Answer
projectile_inputs.m
function [v0,Theta,t]=projectileinputs()
v0 = input("Please enter the initial Velocity (v0) [m/s]: ");
Theta = input("Please enter the angle of departure (Theta) [deg]: ");
t = input("Please enter the instantaneous time (t) [s] : ");
end
projectile_motion.m
function [tf,R,H,x,y]=projectile_motion(v0,Theta,t)
g = 9.8;
tf = (2*v0*sind(Theta))/g;
R = (v0.^2*sind(2*Theta))/(g);
H = (v0.^2*sind(2*Theta))/(2*g);
x = v0*cosd(Theta)*t;
y = v0*sind(Theta)*t - 1/2*g*t.^2;
end
projectile_trajectory.m
function projectile_trajectory(v0,Theta,tf,x1,y1)
x0 = 0;
y0 = 0;
Theta = 60;
g = 9.81;
t = 0:.01:tf;
x = x0 + v0*cosd(Theta)*t;
y = y0 + v0*sind(Theta)*t - g*t.^2/2;
plot(x,y,x1,y1,'r.');
xlabel('x position[m]');
ylabel('y position[m]');
title('Projectile Trajectory');
end
main.m
[v0,Theta,t]=projectile_inputs();
[tf,R,H,x,y]=projectile_motion(v0,theta,t);
fprintf('The total flight time is (tf) : ',tf);
fprintf('The total horizontal travelled distance (R) is : ',R);
fprintf('The max height (H) is :',H);
fprintf('The [x,y] position of projectile at time t=%d s is [%d m, %d m]',t,x,y);
projectile_trajectory(v0,Theta,tf,x,y);