Hi everyone, Can I have some help plotting a projectile motion graph of x vs. y?
3 views (last 30 days)
Show older comments
I've already created two functions, one which asks for user inputs and another that uses the inputs to solve the projectile motion equations. Now I need to graph x vs. y.
1) function [theta,v0,t]= projectile_inputs
v0=input('Please input the initial velocity (v0) [m/s]:');
theta=input('Please input the angle of departure (theta) [deg]:');
t=input('Please input the instantaneous time (t) [s]:');
%Check for valid user inputs
while t < 0 theta < 0 theta > 90;
disp('Sorry! Your inputs are invalid');
v0=input('Please input the initial velocity (v0) [m/s]:');
theta=input('Please input the angle of departure (theta) [deg]:');
t=input('Please input the instantaneous time (t) [s]:');
end
end
2) function [tf,R,H,x,y]= projectile_motion(theta,v0,t)
%Calcualte, tf, R, H, and [x,y]
tf=(2*v0*sind(theta))/9.81;
H=(v0*v0*(sind(theta))^2)/(2*9.81);
R=(v0*v0*(sind(2*theta)))/9.81;
x=v0*cosd(theta)*t;
y=v0*sind(theta)*t - .5*9.81*t^2;
3) Here's what I have for the third function:
function [x1,y1,ti]= projectile_trajectory(v0,theta,tf)
ti=(0:tf);
x1=v0*cosd(theta)*ti;
y1=v0*sind(theta)*ti - 9.81*ti.^2/2;
figure,
plot(x1,y1,'k'); % Plot x1 vs. y1
xlabel('x position [m]'); % Label x-axis
ylabel('y position [m]'); % Label y-axis
title('Trajectory of the Projectile'); %Title the Plot
For some reason, it'll print y1 as a 1x6 vector : 0 1 2 3 4 5 and the graph will come out as a weird parabola that doesn't accurately show that y1=0 at tf. I'm pretty sure, I'm making some dumb mistake (I am a beginner) with the equation of y1, and I'd be really grateful if someone could point out what it is.
0 Comments
Accepted Answer
Image Analyst
on 18 Oct 2017
Sorry, I have no time tonight to go over your code, but I'm attaching my projectile demo that calculates and plots virtually anything you could possibly want (after setting the parameters to what your values should be rather than the demo values). Adapt as needed.
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!