필터 지우기
필터 지우기

How to create multiple velocities with one angle-projectile motion

조회 수: 1 (최근 30일)
Peter Carchia
Peter Carchia 2021년 4월 9일
답변: Milan Bansal 2024년 4월 3일
hello, I am creating a code for projectile motion and I have my code set up where I can create multiple graphs at once where the there are different angles. How could I create another code where there are different velocities with one angle. Thanks. This is what I have right now...
%Projectile motion of a golf ball (no air resistance)
t = 0:.5:7.8; %time vector
u = 41; %inital velocity
angle = [25; 55; 85] %optimal angle
theta = unitsratio ('rad','deg')*angle
g = 9.8;
ux =u.*cos(theta); %velocity x direction
uy = u.*sin(theta) %velocity y direction
x = ux*t; %equation of motion, constant velocity
y= uy*t -0.5*g*t.^2; %equation of motion, constant velocity, resisted by gravity
for j = 1:size(angle,1)
for i = 1:size(x,2)
% if(i>1) && (y1(i)<0) %stop plotting when ball hits the ground
% break;
% end
plot (x(j,i),y(j,i),('*'));
hold on;
pause(0.01);
end
end
title 'flight of golf ball'
xlabel 'meters'
ylabel 'meters'
hgreen = plot(x1, y1, 'g-');
hblack = plot(x2, y2, 'k-');

답변 (1개)

Milan Bansal
Milan Bansal 2024년 4월 3일
Hi Peter Carchia,
To create multiple graphs for the trajectories of projectile motions at different velocities while keeping the angle of incidence the same, please calculate the coordinates of the paths at the different velocities and the given angle, and then iterate over the velocity instead to plot all the trajectories. Please refer to the below code snippet to modify your code.
%Projectile motion of a golf ball (no air resistance)
t = 0:.5:7.8; %time vector
u = [20 40 60]; % initial velocities (change this vector as per the need)
angle = 45; % constant angle of incidence;
theta = unitsratio ('rad','deg')*angle;
g = 9.8;
ux =u.*cos(theta); %initial velocities x direction
uy = u.*sin(theta); %initial velocities y direction
x = ux.'*t; % x coordinates of trajectory at different initial velocity
y= uy.'*t -0.5*g*t.^2; % y coordinates of trajectory at different initial velocity
for j = 1:size(u,2) % iterating over the velocity vector.
for i = 1:size(x,2)
% if(i>1) && (y1(i)<0) %stop plotting when ball hits the ground
% break;
% end
plot (x(j,i),y(j,i),('*'));
hold on;
pause(0.01);
end
end
title 'flight of golf ball'
xlabel 'meters'
ylabel 'meters'
Hope this helps!

카테고리

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