MATLAB: I have to plot 3 curves on a single graph.

graphingprojectilemotion

m=0.000185; %mass of ball (slugs)
k=0.83; %spring constant (lb/ft)
theta=45; %launch angle (degrees)
hd=[7,8,9]; %horizontal distance required (ft)
g=32.2; %gravity (ft/s^2)
v0=sqrt((g*hd)/(2*sin(theta)*cos(theta))); %calculates initial velocity needed for the ball to hit 7,8, and 9 feet (ft/s^2)
s=v0*sqrt(m/k)*12; %distance the spring must be compressed in order to achieve the three initial velocities (in)
vx=v0*cos(theta); %initial velocity in the x direction (ft/s^2)
vy=v0*sin(theta); %initial velocity in the y direction (ft/s^2)
t=vy/g; %time the ball is in the air (s)
y=vy.*t-0.5*g.*t.^2; %maximum vertical distance achieved (ft)
x=2*vx.*t; %horizontal distance achieved (ft)
plot(x,y)
Here is my code so far. I need to plot the three curves on a single graph, but it just keeps outputting a straight line. Not really sure how to fix this.

Best Answer

Try something like this:
tf=vy/g; %time the ball is in the air (s)
t = (0:0.1:2)' * tf; % Create Matrix Of ‘t’ Values
y=vy.*t-0.5*g.*t.^2; %maximum vertical distance achieved (ft)
x=2*vx.*t; %horizontal distance achieved (ft)
plot(x,y)
Experiment with this approach to get the result you want.
Related Question