Help plotting a projectile motion graph

22 visualizzazioni (ultimi 30 giorni)
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 Commenti
Shawn Wachter
Shawn Wachter il 30 Gen 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 il 30 Gen 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.

Accedi per commentare.

Risposta accettata

Image Analyst
Image Analyst il 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]);

Più risposte (0)

Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by