Help plotting a projectile motion graph

22 次查看(过去 30 天)
Hello, I'm trying to plot a projectile motion graph at the given angles using this code.
clear all
angle=[0.4, 0.6, pi/4, 1.0, 1.2];
V0=120;
g=-9.8
t=0:.01:500;
Ax=0;
Ay=g;
x=V0*cos(angle);
y=V0*sin(angle)-9.8*t;
plot(x,y);
I'm a novice when I comes to coding, could someone help me fix this code so that I could plot 5 projectile motion graphs for the 5 given angles
  2 个评论
Shawn Wachter
Shawn Wachter 2021-1-30
Perhaps the following line needs correction: y=V0*sin(angle)-9.8*t;.
I think you want to use t**2, as shown here: y=V0*sin(angle)-9.8*t^2;
Hope this helps!
Image Analyst
Image Analyst 2021-1-30
Yes, that's what I showed him 8 years ago in the Answer section below.
y = yVelocity .* t + (1/2) * Ay .* t.^2;
In the future, you can get credit in terms of reputation points if you post an Answer in the answer section below, but not up here in the comments section which is used to ask posters to clarify their question.

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2013-4-21
Close, but you need to have a loop over the angle. Try this. Use a smaller max time if you want to notice the projectile actually going up before it falls.
clc;
clear all
workspace;
format compact;
format long g;
angle = [0.4, 0.6, pi/4, 1.0, 1.2];
V0 = 120;
g = -9.8;
t = 0 : .01 : 500;
Ax = 0;
Ay= g;
numberOfAngles = length(angle);
for k = 1 : numberOfAngles
thisAngle = angle(k);
xVelocity = V0 * cos(thisAngle);
yVelocity = V0 * sin(thisAngle);
x = xVelocity .* t + (1/2) * Ax .* t.^2;
y = yVelocity .* t + (1/2) * Ay .* t.^2;
subplot(2, 3, k);
plot(x, y, 'b-', 'LIneWidth', 3);
caption = sprintf('Angle = %.3f radians = %.2f degrees\n', ...
thisAngle, thisAngle*180/pi);
title(caption, 'FontSize', 15);
grid on;
xlim([0 6e4]);
end
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-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