Dogs Do Calculus

Andy Long, MAT128
Spring, 2024

Based on the article "Do Dogs Know Calculus?", by Tim Pennings :

Clear[x,y,r,s,slope]

So the theoretical relationship between y and x is purely linear,  with a slope of

Clear[r,s,m,g]
slope=1/Sqrt[(r/s)^2-1]

time[y_]:=(z-y)/r+Sqrt[x^2+y^2]/s
time'[y]
solns=Solve[time'[y]==0,y]

I think that we can agree that the negative answer probably doesn’t make sense....

The data is included in the article as a table: I’ve transcribed it here:

x={10.5,17.0,4.7,10.9,15.3,7.2,15.6,11.6,11.2,11.8,10.3,6.6,11.5,15.0,7.5,11.7,14.0,9.2,14.5,11.5,12.2,13.4,13.5,6.0,12.7,19.2,6.5,14.2,14.5,6.6,11.4,11.8,14.2,12.5,15.3};
y = {2.0,2.1,0.9,2.2,2.3,1.0,3.9,2.2,1.3,2.2,1.8,1.0,1.8,3.8,1.4,1.5,2.6,1.7,1.9,2.1,2.3,1.5,1.8,0.9,2.3,4.2,1.0,1.9,2.0,0.8,1.3,2.4,2.5,1.5,3.3};
data=Transpose[{x,y}];

“I also omitted the couple of times  when Elvis, in his haste and excitement, jumped immediately into the water and swam the entire distance. I figured that even an ‘A’ student can have a bad day.”

We'll need Elvis's parameters for speeds, on land and in the water:

These give average speeds of (r for running, s for swimming):

r=Mean[20/{3.20,3.16,3.15,3.13,3.10}]
s=Mean[10/{12.13,11.15,11.07,10.75,12.22}]
slope

(although Timothy took the average of only the top three speeds in his analysis). 

I might argue for median speeds, rather than means:

r=Median[20/{3.20,3.16,3.15,3.13,3.10}]
s=Median[10/{12.13,11.15,11.07,10.75,12.22}]
slope

Let's look at some plots, of data versus the theoretical model from the optimization model of calculus:

dataplot=ListPlot[data,AxesOrigin->{0,0},PlotLabel->"Elvis Data and theoretical model",AxesLabel->{"x","y"},AxesLabel->Automatic];
theoreticalmodelplot=Plot[slope x,{x,0,20},PlotStyle->{Black,Dashed}];
Show[{dataplot,theoreticalmodelplot}]

Here we use linear regression to find the optimal slope, that minimizes the sum of squares.

lm=LinearModelFit[data,t,t,IncludeConstantBasis->False]
regressionmodelplot=Plot[lm[x],{x,0,20},PlotStyle->Red,AxesLabel->{"x","y"},AxesLabel->Automatic];
lm["ParameterTable"]

Show[
dataplot,
theoreticalmodelplot,
regressionmodelplot,
Frame->True,
PlotLabel->"Elvis Data, regression model (solid), and theoretical model (dashed)"
]

Here we use calculus to find the slope -- that’s what linear regression does, too! And we get the same answer, of course:

f[m_]:=Sum[(y[[i]]-m*x[[i]])^2,{i,1,35}]
Solve[f'[m]==0, m]

GraphicsGrid[{{ListPlot[lm["FitResiduals"],PlotLabel->"Residuals",PlotRange->Automatic],
Histogram[lm["FitResiduals"]]}}]