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?
roots_and_optimization/projectile.m
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
15 lines (14 sloc)
946 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); | |
%independant variables are inserted into the function, magnitude of the velocity and the angle of launch. | |
angle_in_radians=theta*(pi/180); %converts degrees to radians. | |
X_0=2.37; %Define given x distance in meters | |
Y_0=1.72; %Define y(0) height in meters | |
g=9.81; %Define force of gravity, m/s^2 | |
t=X_0/(v_mag*cos(angle_in_radians)); %time value solved in seconds | |
h=Y_0+v_mag*sin(angle_in_radians)*t-(1/2)*g*t^2; %final height, in meters | |
fprintf('the final height of your projectile is %f\n',h) %display of output info in coherent sentence. | |
time_interval=0:0.01:t; %Define time interval in vector form (seconds) | |
x_interval=v_mag*cos(angle_in_radians)*time_interval; %Define x distance interval in vector form (meters) | |
y_interval=Y_0+4*sin(angle_in_radians)*time_interval-(1/2)*g*time_interval.^2; %Define y distance interval in vector form (meters) | |
setdefaults %Setting the defaults | |
end |