How do I create a projectile motion code with inputs that outputs a graph?

1 回表示 (過去 30 日間)
Jake Rahm
Jake Rahm 2019 年 12 月 15 日
回答済み: Alexandra McClernon Ownbey 2019 年 12 月 15 日
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?

回答 (1 件)

Alexandra McClernon Ownbey
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.

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by