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

回答(1 个)

Image Analyst
Image Analyst 2017-4-26
编辑:Image Analyst 2017-4-26

0 个投票

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

1 个评论

Thanks, I will give it a read and see what I can do with it. Appreciated.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by