Help plotting a projectile motion graph

22 Ansichten (letzte 30 Tage)
Michael
Michael am 20 Apr. 2013
Kommentiert: Image Analyst am 30 Jan. 2021
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 Kommentare
Shawn Wachter
Shawn Wachter am 30 Jan. 2021
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 am 30 Jan. 2021
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Image Analyst
Image Analyst am 21 Apr. 2013
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]);

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by