% Projectile Motion % January 2014 % Adapted by Sonia Bhaskaran, February 2026 % This is a comment; MATLAB will not execute clear all % clear all variables close all % close any existing figure windows clc % clear the Command Window % Define our variables v0 = 40; % [m/s] g = 9.81; % [m/s^2] theta = pi/4; % [radians] --> sin()/cos() require input to be radians, sind()/cosd() require input to be degrees dt = 0.1; % [s] must define this before t vector! t = 0:dt:10; % [s] % Calculate projectile's position x = v0*t*cos(theta); y = v0*t*sin(theta) - 0.5*g*t.^2; % note the element-wise multiplication here! % Plotting plot(x, y); % reference help function for other plotting options title('Projectile Motion'); xlabel('Distance, x [m]'); % "el" not "le" ylabel('Height, y [m]'); ylim([0 70]); %% What if we want to plot raw data instead of theoretical data? x_meas = [0 28 57 85 113 141]; % [m] measured x coordinates y_meas = [0 23 37 41 35 19]; % [m] measured y coordinates % Create a scatter plot of x and y coordinates figure hold on scatter(x_meas, y_meas, 'filled') % Overlay the theoretical data plot(x,y) title('Measured Projectile Motion') xlabel('Distance, x [m]'); ylabel('Height, y [m]'); ylim([0 70]); legend('Measured Data', 'Theoretical Data');