Filter löschen
Filter löschen

How to create multiple velocities with one angle-projectile motion

1 Ansicht (letzte 30 Tage)
Peter Carchia
Peter Carchia am 9 Apr. 2021
Beantwortet: Milan Bansal am 3 Apr. 2024
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-');

Antworten (1)

Milan Bansal
Milan Bansal am 3 Apr. 2024
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!

Kategorien

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

Community Treasure Hunt

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

Start Hunting!

Translated by