function maxangle = nonlinair1 %NONLINAIR1: MATLAB function M-file that computes the angle %of maximum distance in the case of nonlinear air resistance. % %Author: Peter Howard maxangle = fminsearch(@negdist, 45.); % 40.685); %Use the angle of maximum distance for the case of linear %air resistance as initial guess. %I.e., minimize the negative of the distance % function d = negdist(theta) %DIST: MATLAB function M-file that takes an angle theta as input %and returns the horizontal distance a dart with initial speed %v0 and air resistance coefficient b v0 = 12.2540; b=.0645; g = 9.81; rhs = @(t,y) [y(2);-b*sqrt(y(2)^2+y(4)^2)*y(2);y(4);-g-b*sqrt(y(2)^2+y(4)^2)*y(4)]; options=odeset('Events',@subevents); [t,y,te,ye,ie]=ode45(rhs,[0 20],[0;v0*cosd(theta);.18;v0*sind(theta)],options); d = - ye(end,1); % function [lookfor stop direction]=subevents(t,y) lookfor = y(3); stop = 1; direction = -1;