% Solve the ``softball'' problem using a shooting method combined with % the secant algorithm. To find: the ball's launch velocity given a % maximum elevation of ypeak. close all clear all clc global Cd Uwind g ypeak % Variable input (mks units where appropriate). Uwind = 13.0/3.6; g = 9.8; Cd = 0.037; theta0 = 24.7*pi/180.0; ypeak = 5.2; % End of variable input. % Specify initial guesses for launch speed. U1 = 10.0; U2 = 40.0; % Use secant-type algorithm to find the launch velocity that gives a % maximum elevation of ypeak. f1 = softball_function(U1,theta0); f2 = softball_function(U2,theta0); delta = U2-U1; count = 1; % Initialize counter. while ( (abs(delta)>1e-6) && (count<1001) ) U3 = U1-f1*(U2-U1)/(f2-f1); fprintf('Iteration=%2.0f\t, Current root estimate=%12.8f\n',count,U3); delta = U3-U2; U1 = U2; f1 = softball_function(U1,theta0); U2 = U3; f2 = softball_function(U2,theta0); count = count+1; end if count==1000 fprint('Maximum number of iterations reached.'); else fprintf('Release velocity (m/s) =%12.8f\n',U3); end