MATLAB: Write a script which will calculate the trajectory of a ball thrown at an initial speed vo (ask the user) over a range of angles (θ = 5o − 85o in 5 degree intervals). Make a plot of your trajectories on a single graph.

dynamicsmathsprojectiletrajectory

Not Sure where I'm going wrong here, any advice/solution will be appreciated. I'm quite new to MatLab btw
v0 = input('Enter Initial Velocity of Ball in m/s and Press Return: ');
angle=(5:5:85);
g=9.81;
t=(2*v0.*sin(angle*(pi/180)))/g;
vx = v0.*cos(angle*(pi/180));
vy = v0.*sin(angle*(pi/180));
sx = vx.*t;
sy=vy.*t-0.5*g.*t.^2;
t = 0 : 0.1:100;
plot(sx,sy);

Best Answer

Hi,
to have all the trajectories in one plot you can use:
v0 = input('Enter Initial Velocity of Ball in m/s and Press Return: ');
angle=(5:5:85);
g=9.81;
hold on
for angle = 5:5:85
tges=(2*v0.*sin(angle.*(pi/180)))/g;
t =linspace(0,tges);
vx = v0.*cos(angle.*(pi/180));
vy = v0.*sin(angle.*(pi/180));
sx = vx.*t;
sy=vy.*t-0.5*g.*t.^2;
plot(sx,sy);
end
hold off
result:
as expected the longest distance is given by 45° angle.
Best regards
Stephan
Related Question