Help plotting a projectile motion graph

조회 수: 22 (최근 30일)
Michael
Michael 2013년 4월 20일
댓글: Image Analyst 2021년 1월 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