Example 4.2.1

This notebook simulates Example 4.2.1 in the text, which discusses finding the best-fitting parabola through 3 points P, Q, and R.  In the window below you may move around the points P, Q, and R by dragging them.  The coordinates of the points will automatically update as will the graph of the best-fitting parabola.  The manipulation does do a check for the rare case of when the points are collinear.  A second manipulation is also included which allows you to enter exact coordinates for the points instead of letting you drag them around.  No evaluation is required to make either work.

Example421[pt1_,pt2_,pt3_]:=Block[ {parabola, rawgraphics, plot, ptlist,x},
If[ Det[ {Join[{1},pt1],Join[{1},pt2],Join[{1},pt3]}]==0, Return[ Plot[0,{x,-30,50}, PlotRange->{-20,50}, AspectRatio->Automatic, PlotLabel-> "There is no parabola fitting these points"]]];
parabola=LinearModelFit[{pt1,pt2,pt3}, {1, x, x^2},x];
rawgraphics={Text["P",pt1,{0,3}], Text["Q",pt2,{0,3}],Text["R", pt3, {0,3}],PointSize[.02], Point[{pt1,pt2,pt3}]};
ptlist= {{"Point P", "Point Q", "Point R"},{{pt1},{pt2},{pt3}}};
Return[Column[{TableForm[ptlist], Show[Plot[parabola[x],{x,-30,50}, PlotRange->{-20,50}, AspectRatio->Automatic, PlotLabel-> parabola[x]],Graphics[rawgraphics], ImageSize->350]}, Alignment->Center]]
]

Finding the parabola through draggable points:

Manipulate[ Example421[pt1,pt2,pt3],{{pt1,{-21,17}}, Locator, Appearance->None},
{{pt2,{9,-6}}, Locator, Appearance->None},
{{pt3,{37,28}}, Locator, Appearance->None},SaveDefinitions->True]

Finding the parabola through entered points:

Manipulate[Example421[pt1,pt2,pt3], {{pt1, {-21,17}, "Point P"}, ControlType->InputField},
{{pt2, {9,-6}, "Point Q"}, ControlType->InputField},
{{pt3, {37,28}, "Point R"}, ControlType->InputField}, SaveDefinitions->True]