Help plotting projectile motion
Show older comments
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
Answers (1)
Image Analyst
on 26 Apr 2017
Edited: Image Analyst
on 26 Apr 2017
0 votes
Attached is my projectile demo. Perhaps that will help. It computes and plots just about everything you can imagine.


1 Comment
Luke Oughton
on 26 Apr 2017
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!