Is there a mistake with my code to calculate ballistic trajectory?
    4 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
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. 
Réponses (1)
  Hiro Yoshino
    
 le 9 Déc 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...
0 commentaires
Voir également
Catégories
				En savoir plus sur Numerical Integration and Differential Equations dans Help Center et File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


