Is there a mistake with my code to calculate ballistic trajectory?

5 views (last 30 days)
function [x,y]= DeLaPena_Trajectory(velocity,angle)
%Fucntion that calculates x and y position of ball
%Inputs: Velocity(m/s) and Angle(degrees)
%Outputs: [x,y]
narginchk(2,2)
%Check for valid inputs
if velocity<0
error('Velocity must be a positive number')
end
if angle<0
error('Angle must be positive')
end
%Defines the velocities
v_x= velocity*cosd(angle); %x-component of v
v_y= velocity*sind(angle); %y-component of v
%Define the displacement equations and time equations
t= (2*v_y)/9.81; %time of ballistic
x= v_x*t; %x-location
y= v_y*t-(1/2)*9.81*t^2; %y-location
This is my user-defined function for ballistic trajectory is there anything wrong with my code, I dont get the same answers as I would when I do it by hand.

Answers (1)

Hiro Yoshino
Hiro Yoshino on 9 Dec 2019
Following the equation of motion
The time the ball reaches the highest point is given by
Yours looks ok though it depends what you want to get from the code...

Categories

Find more on Physics in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!