plot projectile motion in mat lab in matlab

To plot projectile motion in MATLAB, you can use the following steps:

  1. Define the initial conditions:

    • Initial velocity (v0)
    • Launch angle (theta)
    • Acceleration due to gravity (g)
  2. Calculate the time of flight (T):

    • T = (2 * v0 * sin(theta)) / g
  3. Create a time vector from 0 to T with small time intervals:

    • t = 0:0.01:T
  4. Calculate the horizontal and vertical positions at each time point:

    • x = v0 * cos(theta) * t
    • y = v0 * sin(theta) * t - (1/2) * g * t^2
  5. Plot the projectile motion:

    • plot(x, y)
    • title('Projectile Motion')
    • xlabel('Horizontal Distance (m)')
    • ylabel('Vertical Distance (m)')

Here is the MATLAB code to implement the above steps:

main.m
v0 = 30;     % initial velocity in m/s
theta = 45;  % launch angle in degrees
g = 9.8;     % acceleration due to gravity in m/s^2

T = (2 * v0 * sin(deg2rad(theta))) / g;
t = 0:0.01:T;

x = v0 * cos(deg2rad(theta)) * t;
y = v0 * sin(deg2rad(theta)) * t - (1/2) * g * t.^2;

plot(x, y);
title('Projectile Motion');
xlabel('Horizontal Distance (m)');
ylabel('Vertical Distance (m)');
382 chars
15 lines

Make sure to adjust the values of v0 and theta according to your specific scenario.

related categories

gistlibby LogSnag