Quadratic approximation of scalar-value function.

Let’s look at a fairly random polynomial f:R^2->R of two variables

f[x_,y_] = Expand[x^2y-5x^2-8x y +2y+x^2 y^3]

Plot3D[f[x,y],{x,-2,2},{y,-2,2},PlotPoints->100]
ContourPlot[f[x,y],{x,-2,2},{y,-2,2},Contours->100]

Let’s look at first and second order Taylor approximations of f centered at the point (2,-1).  We could obtain these by finding all the first and second order partial derivatives of f at (2,-1), but since P is a polynomial, we can simply plug (x,y)=(2+s,-1+t) into f[x,y], expand, and keep the terms of appropriate degree.

P[s_,t_]=Expand[f[2+s,-1+t]]

P1[s_,t_] = -14-20s+2t

P2[s_,t_] = P1[s,t] -7s^2+8s t -12 t^2

Now let’s compare P (blue) with its first (red) and second (green) order Taylor approximation about (s,t) = (0,0) (which corresponds to (x,y) = (2,-1)).

Plot3D[{P[s,t],P1[s,t],P2[s,t]},{s,-1,1},{t,-1,1},PlotStyle->{Blue,Red,Green},PlotPoints->100]

The graph of the first order Taylor polynomial is the tangent plane to the graph of P. To see what new information is conveyed by the 2nd order approximation, it is useful to plot the difference(in red) between the approximations.

Plot3D[{0,P2[s,t]-P1[s,t]},{s,-.1,.1},{t,-.1,.1},PlotStyle->{Blue,Red,Green},PlotPoints->100]

So in this instance, the contribution of the 2nd order terms is purely negative, causing the graph of P to bend down from its tangent plane in all directions at (x,y)=(2,-1).  This kind of information is most valuable when considering the behavior of a function near a critical point.  Note from the contourplot above that f seems to have a critical point somewhere near (-.5,.5).  Let’s find it and look at the behavior of f there.

grad[x_,y_]=D[f[x,y],{{x,y}}]

{x,y}/.Solve[grad[x,y]==0,{x,y}]//N

The critical point we see must be (x,y) = (0.261771,-0.353213).

P[s_,t_]=Expand[f[.261771+s,-.353213+t]]

P2[s_,t_]=-0.3365821335946064`+1.417371623069208`*^-6 s-5.397279650206435` (s^2)+3.1217464520894023`*^-6 t-7.280507605911641` s t-0.07261076264308479` (t^2)

P1[s_,t_]=-0.3365821335946064`+1.417371623069208`*^-6 s+3.1217464520894023`*^-6 (t^2)

Note this time that the linear approximation of f at the critical point is more or less constant (as it should be).  Let’s plot this constant together with the (recentered) function and then together with the quadratic approximation.

Plot3D[{P[s,t],P1[s,t]},{s,-.1,.1},{t,-.1,.1},PlotStyle->{Blue,Red,Green},PlotPoints->100]
Plot3D[{P2[s,t],P1[s,t]},{s,-.1,.1},{t,-.1,.1},PlotStyle->{Blue,Red,Green},PlotPoints->100]

As we should expect.  P is quite close to its quadratic approximation near the critical point.  In particular, we can see simply from looking at the quadratic approximation that the critical point is a “saddle” (i.e. neither a local maximum nor a local minimum).