function maxangle = linair2 %LINAIR2: MATLAB function M-file that computes the angle %of maximum distance for the case of linear air resistance. %Author: Peter Howard maxtemp = fminsearch(@negdist,.7771); %Use the angle of maximum distance for the case of no %air resistance as initial guess. maxangle = maxtemp*180/pi; %I.e., minimize the negative of the distance % function value = negdist(theta) %NEGDIST: MATLAB subfunction that takes an %angle theta (in radians) as input and returns %negative of distance traveled. g = 9.81; H = .18; b = .2792; v = 11.2343; %The implicit equation for distance d is f = @(d) H + (g/b^2)*log(1-b*d/(v*cos(theta))) + (v*sin(theta)/b+g/b^2)*b*d/(v*cos(theta)); guess = 10.26*cos(theta)*(10.26*sin(theta)+sqrt(10.26^2*sin(theta)^2+2*H*g))/g; %I.e., why not use the distance associated with no air resistance as an %initial approximation. value = -fzero(f,guess);