> 
interface( warnlevel = 0 ):

> 
m := 0.145: #mass of baseball

> 
C_d := 0.35: #drag coefficient

> 
y0 := 1.5: #y(0): height from which ball is hit

> 
yf := 2.5: #height of homerun fence

> 
xf := 114: #rightcenter field homerun distance

> 
v_x := diff( x(t), t ):

> 
v_y := diff( y(t), t ):

> 
eqx := diff( v_x,t) = ((C_d)*rho*Pi*(r^2)*(v_x)*sqrt((v_x)^2 +(v_y)^2))/(2*m):

> 
eqy := diff( v_y,t) = ((C_d)*rho*Pi*(r^2)*(v_y)*sqrt((v_x)^2 +(v_y)^2))/(2*m)g:

> 
ics := x(0) = 0, y(0) = y0, D(x)(0) = v0*cos(alpha), D(y)(0) = v0*sin(alpha):

> 
Sol := dsolve( { eqx, eqy, ics }, numeric, parameters = [ v0, rho, xhalt, alpha ],

> 
events = [ [x(t)  xhalt, halt] ], output = listprocedure ):

> 
Y := eval( y(t), Sol ):

> 
HeightatHalt := proc( v0, rho, xtarget, angle )

> 
Y( parameters = [ :v0 = v0, :rho = rho, :xhalt = xtarget, :alpha = angle ] );

> 
Y( 200 ); # 200 second airborne limit

> 
# smallest v0 which will attain rightcenter home run at # sea level air resistance and angle alpha = Pi/4. v_sealevel := fsolve( 'HeightatHalt'( v0, 1.2, xf, Pi/4 ) = yf, v0 = 30..100 );

> 
# smallest v0 which will attain rightcenter home run at # Denver air resistance and angle alpha = Pi/4. v_denver := fsolve( 'HeightatHalt'( v0, 1.2*0.9, xf, Pi/4 ) = yf, v0 = 30..100 );

> 
# smallest angle to get home run with v0 = v_sealevel # and sea level air resitance. alpha_low[v_sealevel,1.2] := fsolve('HeightatHalt'( v_sealevel, 1.2, xf, alpha )  yf = 0, alpha=0..Pi/4 ); # := rhs( Minimize( alpha # + ('HeightatHalt'( v_sealevel, 1.2, xf, alpha )  yf)^2, # method = nonlinearsimplex )[2,1] );

> 
# smallest angle to get home run with v0 = v_sealevel # and Denver air resitance. alpha_low[v_sealevel,1.2*0.9] := fsolve('HeightatHalt'( v_sealevel, 1.2*0.9, xf, alpha )  yf = 0, alpha=0..Pi/4 ); # := rhs( Minimize( alpha # + ('HeightatHalt'( v_sealevel, 1.2*0.9, xf, alpha )  yf)^2, # method = nonlinearsimplex )[2,1] );

> 
# largest angle to get home run with v0 = v_sealevel # and Denver air resitance. alpha_high[v_sealevel,1.2*0.9] := fsolve('HeightatHalt'( v_sealevel, 1.2*0.9, xf, alpha )  yf = 0, alpha=Pi/4..Pi/2 );

> 
# smallest angle to get home run with v0 = v_denver # and Denver air resitance. alpha_low[v_denver,1.2*0.9] := fsolve('HeightatHalt'( v_denver, 1.2*0.9, xf, alpha )  yf = 0, alpha=0..Pi/4 ); # := rhs( Minimize( alpha # + ('HeightatHalt'( v_denver, 1.2*0.9, xf, alpha )  yf)^2, # method = nonlinearsimplex )[2,1] );

> 
with(plots): display( # Pi/4 was originally used to find v_sealevel, v_denver plot( Pi/4, v0=43..50, color=black ), plot( [v_denver, alpha, alpha=0..Pi/4], color=blue, linestyle=dot ), plot( alpha_low[v_denver,1.2*0.9], v0=43..v_denver, color=blue, linestyle=dash ), implicitplot( 'HeightatHalt'( v0, 1.2*0.9, xf, alpha )  yf, v0=43..50, alpha=0..Pi/2, gridrefine=2, color=blue ), plot( [v_sealevel, alpha, alpha=0..alpha_high[v_sealevel,1.2*0.9]], color=red, linestyle=dot ), plot( alpha_low[v_sealevel,1.2], v0=43..v_sealevel, color=red, linestyle=dash ), plot( alpha_low[v_sealevel,1.2*0.9], v0=43..v_sealevel, color=red, linestyle=dash ), plot( alpha_high[v_sealevel,1.2*0.9], v0=43..v_sealevel, color=red, linestyle=dash ), implicitplot( 'HeightatHalt'( v0, 1.2, xf, alpha )  yf, v0=43..50, alpha=0..Pi/2, gridrefine=2, color=red ), axis[2] = [tickmarks=piticks], # or use decimalticks view = [43..50, 0..3*Pi/8], labels = [v0, alpha] );

