I AM WANTING TO STOP PLOTTING ONCE Y < 0.
%{
This function was created by Taylor McMillan.PURPOSE: Model simple projectile motion. Introduce students to Matlab.ENTER THE FOLLOWING INTO THE COMMAND WINDOW:ProjectileMotion(0.1, 0, 0, 50, pi/4, 30)%}
%%START PROGRAM %%
function ProjectileMotion(time_step, xic, yic, vic, angic, max_time)%%Create A Time Series %%
h = time_step;N = max_time/h;t = 0:h:max_time - h;%%Initial Conditions / Parameters %%
x(1) = xic; % Initial x-position (meters)
y(1) = yic; % Initial y-position (meters)
v(1) = vic; % Initial speed (meters/second)
ang(1) = angic; % Initial launch angle (radians)
g = 9.81; % Acceleration due to gravity (meters/second/second)
%%Projectile Equations %%
if y >=0 && x >= 0 x = x(1) + v(1)*cos(ang(1))*t; y = y(1) + v(1)*sin(ang(1))*t - 0.5*g*t.^2;%%Plot The Motion %%
else figure(); plot(x, y) xlabel('x - position (m)', 'FontSize', 20) ylabel('y - position (m)', 'FontSize', 20) title('Trajectory', 'FontSize', 26)end
END PROGRAM %%
end
Best Answer