To plot trajectory based on x and y velocity in matlab, we need to first define the variables for x and y velocity, initial velocity and the angle of projection. We can use the following code to generate the trajectory plot:
main.m636 chars23 lines
In this code, we have defined the initial velocity of the projectile as u
and the angle of projection as theta
. We have then calculated the x and y components of velocity (ux
and uy
) and defined the time interval and time vector using dt
and t
. Using these values, we have then calculated the x and y positions of the projectile (x
and y
) using the projectile motion equations.
Finally, we have plotted the trajectory using the plot()
function, with x
and y
as the input arrays. The rest of the code defines the axes labels and the plot title, and turns on the gridlines for better visualization.
gistlibby LogSnag