It Seems there’s a bit o’ error in the Max Distance formula... p. 203

p. 203: the max distance formula is wrong by a bit
Andy Long
MAT360
Spring 2017

Clear[a,c,b,y1,y2,y3,m]
c=(a+b)/2
m=(y3-y1)/(b-a)
l[x_]:=y1+m(x-a)
p[x_]:=y1*(x-c)(x-b)/((a-c)(a-b))+ y2*(x-a)(x-b)/((c-a)(c-b))+ y3*(x-a)(x-c)/((b-a)(b-c))

p interpolates as we can see:

Simplify[p[a]]
Simplify[p[c]]
Simplify[p[b]]

Let’s see where the quadratic has slope equal to the secant line joining the endpoints:

Solve[D[p[x],x]==m]

Heh! Interesting, it’s at c.

Now we’ll solve for the intersection of the perpendicular through the point (c,p(c)), and the secant line: that will be the greatest distance between the two (see Figure 5.18, p. 203):

xroot=Replace[x,Simplify[Solve[y2-(1/m)(x-c)==l[x],x]]][[1]]

Now we compute the distance between (c,p(c)) and (xroot,l(xroot)), and simplify it:

dist[a_,fa_,b_,fb_]=Sqrt[(fb-fa)^2+(b-a)^2]
Simplify[dist[xroot,l[xroot],c,p[c]]]

The distance formula is different! I call mine maxDtoo, and theirs maxD:

maxD[a_,c_,y1_,y2_,y3_]:=(c-a)/8*Abs[y1 - 2*y2 + y3]/
    Sqrt[(c-a)^2 + (y2 - y1)^2]
maxDtoo[a_,b_,y1_,y2_,y3_]:=(1/2)*Sqrt[((a - b)^2*(y1 - 2*y2 + y3)^2)/
    (a^2 - 2*a*b + b^2 + (y1 - y3)^2)]

Mine disagrees with theirs on their example, p. 203:

maxDtoo[1,2,1,2/3,1/2]
%*1.0

But their’s gets the answer wrong on one whose result is elementary: a parabola whose peak is at c, and which is equal at a and b:

maxDtoo[1,3,1,2,1]
maxD[1,2,1,2,1]

a=0
b=2
y1=1
y2=3
y3=2
p1=ListPlot[{{a,y1},{c,y2},{b,y3},{xroot,l[xroot]}},PlotStyle->PointSize[Large]];
p2=Plot[{p[x],y1+(y3-y1)(x-a)/(b-a),y2+m(x-c),y2-(1/m)(x-c)},{x,a,b},AspectRatio->2];
Show[p1,p2,AspectRatio->1.6]
dist[c,p[c],xroot,l[xroot]]
maxD[a,c,y1,y2,y3]
maxDtoo[a,b,y1,y2,y3]