Is there a mistake with my code to calculate ballistic trajectory?
3 ビュー (過去 30 日間)
古いコメントを表示
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.
回答 (1 件)
Hiro Yoshino
2019 年 12 月 9 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Numerical Integration and Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!