Help plotting projectile motion

Ok, I have no idea what's wrong. I am awful at Matlab T_T. Anyway, it is plotting in yellow and it is not a parabola as I would have expected. Sorry and thanks in advance for any help.
if yh0 == 0
tmax = (2*yv0) / g; %Calculates the time of flight t = 2*Yvelocity / g
for t = 1:0.01:tmax %When t is less than the time of flight keep looping
y_v(L) = y_v(L-1) + ( -g.*t );
y_s(L) = ( y_v(L-1).*t ) + ( 1/2*-g.*t.^2 );
%Horizontal
x_v = xv0; %Horizontal doesn't change (acc=0)
x_s(L) = xv0.*t; %Horizontal displacement
L=L+1;
end
elseif yh0 > 0
tmax = (yv0 / g) + (sqrt(((yv0)^2) + 2*g*yh0))/ g;
for t = 0:1:tmax %When t is less than the time of flight keep looping
L=L+1; %Adds a counter each time the loop runs
y_v(L) = y_v(L-1) + g.*t; %Calculates the Y velocity v = u+at
y_s(L) = y_v(L-1).*t + 1/2*g.*t.^2; %Calculates the Y displacement s = ut + 1/2at^2
%Horizontal
x_v = xv0; %Horizontal doesn't change (acc=0)
x_s(L) = xv0.*t; %Horizontal displacement
MaxH= (v0^2 * sind(theta)^2 )/ 2*g;
end
end
%========================================================================%
% %
% PLOTTING PROJECTILES %
% %
%========================================================================%
figure %Opens in a new figure window
plot(x_s, y_s, 'ro', 'MarkerSize', 6, 'MarkerEdgeColor', [1 1 0], 'MarkerFacecolor', [.2 .2 1]);
title(' Projectile Motion '); %Adds a title to the graph
xlabel(' Distance (M) '); %Yup
ylabel(' Height (M) '); %Is what it says

Réponses (1)

Image Analyst
Image Analyst le 26 Avr 2017
Modifié(e) : Image Analyst le 26 Avr 2017

0 votes

Attached is my projectile demo. Perhaps that will help. It computes and plots just about everything you can imagine.

1 commentaire

Luke Oughton
Luke Oughton le 26 Avr 2017
Thanks, I will give it a read and see what I can do with it. Appreciated.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by