Is there a mistake with my code to calculate ballistic trajectory?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
Respuestas (1)
Hiro Yoshino
el 9 de Dic. de 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 comentarios
Ver también
Categorías
Más información sobre Numerical Integration and Differential Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!