function dvec = distvec(v0,b) %DISTVEC: MATLAB function M-file that takes as input %initial speed v0 and air resistance coefficient b %and returns a vector of distances at the angle 5:5:85 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); for j=1:17 theta = j*5; [t,y,te,ye,ie]=ode45(rhs,[0 20],[0;v0*cosd(theta);.18;v0*sind(theta)],options); dvec(j) = ye(1); end % function [lookfor stop direction]=subevents(t,y) lookfor = y(3); stop = 1; direction = -1;