You are on page 1of 2

11/7/23 4:36 PM E:\Desktop\To Be Shifted\Matla...\SUS45.

m 1 of 1

% Constants
g = 9.81; % Acceleration due to gravity (m/s^2)
theta = 45; % Launch angle (degrees)
t = 0:0.01:5; % Time vector

% Velocities to plot
velocities = [1, 25, 50]; % m/s

% Initialize plot
figure;
hold on;

for v = velocities
% Calculate initial velocity components
v_x = v * cosd(theta); % Horizontal component
v_y = v * sind(theta); % Vertical component

% Calculate horizontal and vertical positions


x = v_x * t;
y = v_y * t - 0.5 * g * t.^2;

% Plot the trajectory for the current velocity


plot(x, y, 'DisplayName', ['v = ' num2str(v) ' m/s']);
end

% Set axis labels and legend


xlabel('Horizontal Distance (m)');
ylabel('Vertical Distance (m)');
legend('Location', 'Best');
title('Projectile Motion for Varying Velocities');
grid on;

% Hold off to prevent further plotting on the same figure


hold off;

You might also like