How do I create a projectile motion code with inputs that outputs a graph?
2 views (last 30 days)
Show older comments
g = 9.8;
Vo = 0;
time = 15;
t = 0:0.1:time;
Theta = 0;
y0 = 0;
Vo = 'What is the Initial Velocity? ';
Vo = input(Vo);
Theta = 'What is the Angle? ';
Theta = input(Theta);
y0 = 'What is the Initial Y position? ';
y0 = input(y0);
x0 = 'What is the Initial X position? ';
x0 = input(x0);
x = x0+Vo*cos(Theta)*t;
y = y0+Vo*sin(Theta)*t-(g*t.^2)/2;
plot (x,y)
I am trying to have the user input all of the variables for a projectile motion code. It seems like the graph is very flat, no matter what degree is entered. I am sure I am missing something for the angle, but I do not know what. I am also having trouble making the graph start at zero, instead of negative (a really large number). Can anyone assist me and explain what I am doing wrong?
0 Comments
Answers (1)
Alexandra McClernon Ownbey
on 15 Dec 2019
Jake,
are you entering your angle in degrees or radians? If you want to use degrees, use cosd and sind. You also don't need to initialize your variables before you input them. If you want to limit your plot manually, you can either use a conditional statement to stop plotting after the projectile reaches zero or change the plot axes limits.
0 Comments
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!