
% Equations of motion for a basketball in 2D
function dqdt = basketball(q, t)
%constants (mks units, NBA men's official size & weight)
m = 0.6237;   % mass of ball, kg (22 oz)
r = 29.5*2.54e-2/2/pi; % radius of ball, m (29.5" circumf)
A = pi*r^2;   % cross-sectional area of ball, m^2
Cd = 0.5;     % approx. drag coefficient for a sphere
rho = 1.2;    % density of dry air, kg m^-3 (20deg C, 1 atm). 
g = 9.81;     % accel of gravity, m s^-2

%state variables:
x = q(1:2);
v = q(3:4);
force = [0,-m*g] - (1/2)*Cd*A*rho*(v*norm(v));
accel = force/m;
dqdt = [v,accel];