How to create multiple velocities with one angle-projectile motion

7 ビュー (過去 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 Center および File ExchangeEarth and Planetary Science についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by