Skip to content
Permalink
4391bceca9
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
31 lines (21 sloc) 871 Bytes
function [h] = projectile(v_mag, theta)
%h = projectile(v_mag, theta)
%This function calculates the height of a projectile at a certain
%distance.
%v_mag = the magnitude of intial velocity in meters per second.
%theta = the angle of inclination of the initial velocity in degrees.
y0 = 1.72; %the initial height of the projectile.
a = -9.81; %downward acceleration due to gravity.
del_x = 2.37; %horizontal displacement
theta = deg2rad(theta); %convert theta to radians.
[vx0,vy0] = pol2cart(theta, v_mag);
y = @(x) .5 * a * (x ./ vx0).^2 + vy0 / vx0 .* x; %anonymous functions FTW?
del_y = y(del_x);
h = del_y + y0; %height at location.
run('setdefault.m');
x = linspace(1,del_x);
y_x = y(x);
h_x = y_x + y0;
%plot trajectory
plot(x, h_x);
end