The Drowning Swimmer

Parameters :

vswim = 1;
vrun = 1;
horizdist = 40;
vertlanddist = 15;
vertwaterdist = 30;
straightlinepoint = (1.0horizdist * vertlanddist / (vertlanddist+vertwaterdist)) ;

Time functions

tland[speed_,vdist_, x_] := Sqrt[x^2 + vdist^2] / speed;
twater[speed_, vdist_, hdist_, x_] := Sqrt[(hdist-x)^2+vdist^2] / speed;
time[speedwater_,speedland_,disthoriz_,distvertland_,distvertwater_,x_] := tland[speedland,distvertland,x] + twater[speedwater,distvertwater,disthoriz,x];

Plot of time as a function of where we run to

Our default values are vswim = 1, vrun = 4, horizdist = 40, vertlanddist = 15, vertwaterdist = 30

Manipulate[Plot[time[1,vvrun,vhorizdist,vvertlanddist,vvertwaterdist,x], {x,0,vhorizdist}, PlotRange -> {10,100}, AxesLabel -> {x, Time}], {vvrun,1,5},{vhorizdist,10,50},{vvertlanddist,10,50},{vvertwaterdist,10,50}]
Print["The value of x if we do the straight line is ", straightlinepoint, "."];
Print[" "];

Time function and its derivative

Print["The time function is ",Simplify[time[vswim,vrun,horizdist,vertlanddist,vertwaterdist,x]], "."];
Print["The derivative is ", Simplify[D[time[vswim,vrun,horizdist,vertlanddist,vertwaterdist,x],x]],"."];
timeasfnx[x_] := time[vswim,vrun,horizdist,vertlanddist,vertwaterdist,x];
Print["We now plot the derivative of the time function (as a function of x)."];
Plot[timeasfnx'[x], {x,0,horizdist}]
Print["The straightline intersection is at x = ", straightlinepoint, "; the optimum is at ", FindRoot[timeasfnx'[x] == 0, {x,straightlinepoint}]];

Manipulate[{timeasfnx[x_] := time[vswim,vrun,horizdist,vertlanddist,vertwaterdist,x],
Plot[timeasfnx'[x], {x,0,horizdist}, PlotRange -> {-1,1}, Epilog -> {PointSize[.025], Point[{straightlinepoint,0}]}, AxesLabel -> {x, "Derivative of time function"}]}, {vrun,1,4}]