% Equations of motion for a basketball in 2D
function dqdt = basketball(q, t)
%constants (mks units)
m = 0.5;      % mass of ball, kg
r = 0.1;      % radius of ball, m
A = 3.14*r^2; % cross-sectional area of ball, m^2
Cd = 0.5;     % drag coefficient for a sphere
rho = 1.0;    % density of air, kg m^-3
g = 10;       % 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];
% that's all.