How do I create a projectile motion code with inputs that outputs a graph?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Alexandra McClernon Ownbey
2019-12-15
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 个评论
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!