Permalink
Cannot retrieve contributors at this time
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?
homework_1/projectile.asv
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
31 lines (21 sloc)
871 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |