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!