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
26 lines (19 sloc) 851 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 + y0; %anonymous functions FTW?
run('setdefault.m');
x = linspace(0,del_x); %x-values to be graphed
y_x = y(x); %calculate y-values for each x;
%plot trajectory
plot(x, y_x);
h = y_x(end);
end