### create a function file that calculates the trajectory of a projectile. The inputs to the function are the initial velocity and the angle at which the projectile is fired. The outputs from the function are the maximum height and distance. In addition, the function generates a plot of the trajectory. Use the function to calculate the trajectory of a projectile that is fired at a velocity of 230 m/sec at an angle of 39deg.

Problem:
create a function file that calculates the trajectory of a projectile. The inputs to the function are the initial velocity and the angle at which the projectile is fired. The outputs from the function are the maximum height and distance. In addition, the function generates a plot of the trajectory. Use the function to calculate the trajectory of a projectile that is fired at a velocity of 230 m/sec at an angle of 39deg.

USING MATLAB SOFTWARE Version 7.0

SOLUTION:-

%Write it in script file
function[hmax,dmax]=trajectory(V0,theta)
g=9.81;
V0x=V0*cos(theta);
V0y=V0*sin(theta);
thmax=V0y/g;
hmax=V0y^2/(2*g);
ttotal=2*thmax
dmax=V0x*ttotal
% creating a trajectory plot
tplot=linspace(0,ttotal,200);
x=V0x*tplot;
y=V0y*tplot-0.5*g*tplot.^2;
plot(x,y)
xlabel('distance (mt)')
ylabel('height(mt)')
title('projectile of Rocket')

>> [height distance]=trajectory(230,39)        %In command window

ttotal =

45.1933

dmax =

2.7716e+003

height =

2.5045e+003

distance =

2.7716e+003 Trajectory of profile