Is there a mistake with my code to calculate ballistic trajectory?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
Antworten (1)
Hiro Yoshino
am 9 Dez. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Numerical Integration and Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!