I have to plot 3 curves on a single graph.

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.

4 commentaires

jonas
jonas le 3 Mai 2018
what three series of data do you want to plot?
Cody Phillips
Cody Phillips le 3 Mai 2018
There are three values of v0, and each of those are divided into x and y components. The code outputs those no problem, but when I try and graph them with respect to time (the x and y equations), I just get a straight line, even though t is quadratic.
jonas
jonas le 3 Mai 2018
Modifié(e) : jonas le 3 Mai 2018
But, as far as I can see there is no vector with time, so you cannot plot the distance travelled over time. Each variable in your code are just single values. Also, shouldn't the last equations be x=vx*t, and y=vy*t/4?
Alfonso
Alfonso le 3 Mai 2018
So you are trying to plot the x and y values respect to time, where time starts at t=0 until t=vy/g, am I right?

Connectez-vous pour commenter.

 Réponse acceptée

Star Strider
Star Strider le 3 Mai 2018
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.

2 commentaires

Cody Phillips
Cody Phillips le 3 Mai 2018
That worked perfectly! Thank you!
Star Strider
Star Strider le 3 Mai 2018
My pleasure!
If my Answer helped you solve your problem, please Accept it!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by