Use MATLAB to program The position of a projectile fired wit
Use MATLAB to program.
The position of a projectile, fired with an initial speed of vo at an angle ?, can be written as a function of time (x(t),y(t)) as
x(t)=vocos(?)tandy(t)=vosin(?)t–0.5gt2
where g=9.81m/s2. The polar coordinates of the projectile (r(t),?(t)) at time t are:
r(t)=x2(t)+y2(t)???????????andtan(?(t))=y(t)x(t)
Write a MATLAB script to calculate the r(t) and ?(t) for input values of vo , ? , and t, provided by the user. Run the program for vo = 150 m/s and ? = 65° at time t = 5, 10, and 20 sec and report the results. Make sure to define your variables clearly and include proper comments in your code.
Solution
%initialising given values for v0, alpha, g and times
v0 = 150;
alpha = 65;
g = 9.81;
times = [5, 10, 20];
%iterating through the times to calculate corresponding values at each time
for t=times
%calculating x
x = v0*cosd(alpha)*t;
%calculating y
y = v0*sind(alpha)*t - 0.5*g*t^2;
%calculating r
r = sqrt(x^2 + y^2);
%calculating theta
theta_t = atand(y/x);
%displaying the values for r and theta at each time t
disp([\'At time t = \', num2str(t), \', r = \', num2str(r), \', theta = \', num2str(theta_t)]);
end
