Plot not displaying lines

13 Ansichten (letzte 30 Tage)
Gerrit Feyen
Gerrit Feyen am 12 Dez. 2021
Kommentiert: Gerrit Feyen am 12 Dez. 2021
I have a simple project here and my plot comes up fine but without any line or points present. Just blank with a scaled X and Y axis. Thoughts?
%Test your might! Who's ball will clear a football field?
disp('Two people see who can throw farther, will they clear the field? Who will win?');
Vi = input('How fast is the first ball released in mph? ');
A = input('At what angle do you release this ball in degrees? ');
Vi1 = input('How fast is the second ball released in mph? ');
A1 = input('At what angle do you release this ball in degrees? ');
%Now we need conversion equations and kinematic equations to find the final
%distances
V_mps = (Vi*0.44704);
A_rad = A*(pi/180);
t_hit = 2*(V_mps/9.8)*sin(A_rad);
dist= ((V_mps*t_hit*cos(A_rad))*1.09361);
t_max = t_hit/2;
x = ((V_mps.*t_max.*cos(A_rad))*1.09361);
y = ((V_mps.*t_max.*sin(A_rad)- 0.5*9.8*t_max^2)*1.09361);
%second throw
V_mps1 = (Vi1*0.44704);
A_rad1 = A1*(pi/180);
t_hit1 = 2*(V_mps1/9.8)*sin(A_rad1);
dist1 = ((V_mps1*t_hit1*cos(A_rad1))*1.09361);
t_max1 = t_hit1/2;
x1 = ((V_mps1.*t_max1.*cos(A_rad1))*1.09361);
y1 = ((V_mps1.*t_max1.*sin(A_rad1)- 0.5*9.8*t_max1^2)*1.09361);
plot (x, y, "r-");
plot (x1, y1, "r--");
%Final if statement to determine if the launch was over or under 100 yards
%and who won
if dist>= 100
fprintf('Player 1, you made it!');
else
fprintf('Player 1, you did not make it :(');
end
if dist1>= 100
fprintf('Player 2, you made it!');
else
fprintf('Player 2, you did not make it :(');
end
if dist> dist1
fprintf('Player 1 wins!');
end
if dist< dist1
fprintf('Player 2 wins!');
end
if dist == dist1
fprintf('It was a tie!')
end

Antworten (1)

Adam Danz
Adam Danz am 12 Dez. 2021
A line requires at least two points. Your x, x1, y, y1 values are scalars (single points). If you want to plot a marker instead of a line,
plot (x, y, "ro"); % circular marker
plot (x1, y1, "rs"); % square marker
Perhaps you meant to plot,
plot ([x, x1], [y, y1], "r-");
  4 Kommentare
Gerrit Feyen
Gerrit Feyen am 12 Dez. 2021
y and y1 were supposed to be the two thrown ball heights, I was copying another set of fuctions for plotting motion with the x and x1 since mine was not working. I want the height of the thrown ball from start to finish plotted as it goes through the air with the y and y1 equations. This is what I just tried and I got errors in my h(t) equations, just what I called y now.
V_mps = (Vi*0.44704);
A_rad = A*(pi/180);
t_hit = 2*(V_mps/9.8)*sin(A_rad);
dist= ((V_mps*t_hit*cos(A_rad))*1.09361);
t_max = t_hit/2;
for t =0:10
h(t) = ((V_mps.*t.*sin(A_rad)- 0.5*9.8*t^2)*1.09361);
t = t+1;
end
%second throw
V_mps1 = (Vi1*0.44704);
A_rad1 = A1*(pi/180);
t_hit1 = 2*(V_mps1/9.8)*sin(A_rad1);
dist1 = ((V_mps1*t_hit1*cos(A_rad1))*1.09361);
t_max1 = t_hit1/2;
for t1 =0:10
h1(t) = ((V_mps1.*t1.*sin(A_rad1)- 0.5*9.8*t1^2)*1.09361);
t1 = t1+1;
end
y1 = ((V_mps1.*t_max1.*sin(A_rad1)- 0.5*9.8*t_max1^2)*1.09361);
plot ([t,t1],[y,y1], "r-");
Among other issues I think I need to define my variables better for the loops, idk I'm not great at this
Gerrit Feyen
Gerrit Feyen am 12 Dez. 2021
*the balls remain in the air for about 5 seconds I believe

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Physics finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by