Multivariable Taylor polynomialsGreg Warrington Modified from a worksheet, "Sec13.9-3dTaylorAnim.mws" by Mike May, S.J.Choose Edit->Execute->Worksheet to run the worksheet.Ignore everything in the "Code" section.
<Text-field layout="Heading 1" style="Heading 1">Code</Text-field>restart: with(plots):(a,b) is the point we wish to center our animation at del determines how far in each direction along the x and y axes we view zval and height takes care of the same issues relative to the z-axis bydeg lets us skip certain Taylor approximations if we want. degsteps determines the highest number Taylor approximation that will be displayedMTaylor := proc(fun,a,b,del,height,mdeg) local mindeg, degsteps, bydeg, lowx, highx, lowy, highy, zval, lowz, highz, labpt, xrange, yrange, zrange, mt, tmp: mindeg := 2: degsteps := mdeg+1: bydeg :=1: lowx := a-del: highx := a+del: lowy := b-del: highy := b+del: zval := evalf(fun(a, b)); lowz := zval-height: highz := zval+height: labpt := [(highx + lowx)/2,lowy,highz]: xrange:= lowx..highx: yrange := lowy..highy: zrange := lowz..highz: tmp := [seq(framer3d(fun(x,y),i,a,b,xrange,yrange,zrange,mindeg,bydeg,labpt), i=0..degsteps)]: display(tmp,insequence = true,style=patch, view=zrange); end:This procedure computes the image for a given Taylor polynomial. Each image contains three elementsA - the graph of the actual function (unchanging)B - the graph of the appropriate Taylor polynomialT1 - a label describing which Taylor polynomial is being described. Note that the third argument to mtaylor is one higher than the degree of the resulting polynomial.framer3d := proc(fun,i,a,b,xrange,yrange,zrange,mindeg,bydeg,labpt) local A, B, T1, deg: deg := mindeg + bydeg*i: A := plot3d(mtaylor(fun,[x=a, y=b], deg), x=xrange, y=yrange, view= zrange, color=blue, style=WIREFRAME,thickness=2): B := plot3d(fun(x,y),x=xrange, y=yrange, view= zrange): T1 := textplot3d([labpt[1],labpt[2],labpt[3], `Degree `||(deg-1)||` Taylor`], align={BELOW,RIGHT}, font=[HELVETICA, BOLD, 12]): display3d({A,B,T1},axes=boxed); end:
Convergence of a multivariable Taylor polynomial.This is an animation that shows the convergence of a multivariable Taylor polynomial to a function of two variables. Everything works analogously to how it works in the one-variable case.Since this is an animation, click on it and then move the slider at the top of the page to move through differentframes and thereby display the Taylor polynomials of different degrees.Note the the "degree" 1 Taylor polynomial is a plane.#################################### del := 2: height := 3: mdeg := 14: g := (x,y) -> sin(x+3*y)+cos(2*x-y): a := Pi/4: b := Pi/3: # MTaylor(g,a,b,del,height,mdeg); #################################### del := 2: height := 3: mdeg := 6: h := (x,y) -> (x^6 + 3*y^2)/10: a := 0: b := 0: # MTaylor(h,a,b,del,height,mdeg); #################################### del := 2: height := 3: mdeg := 26: j := (x,y) -> exp(x-y^2): a := 0: b := 0: MTaylor(j,a,b,del,height,mdeg); Radius of convergenceThis animation illustrates the error between a function of two variables and its Taylor polynomial approximations. In single variable Taylor polynomials we learned that the Taylor series of some functions have a finite radius of convergence. It is instructive to look at what happens in the 2 variable case. Consider the function h(x,y) = 1/(x^2+y^2) approximated by Taylor polynomials centered at (2,1). It is clear that we will never have a good approximation that includes the origin. What we get is an approxiamtion that is good in a circular region with a radius small enough to exclude the trouble spot at the origin.The following animation plots the error between a function and its Taylor approximation for a given degree.As the order increases, the approximation gets better and the error (i.e., plot) gets closer to 0 in a larger portion of the (x,y)-plane.As the order increases, though, the error goes wild outside of a circle centered at (2,1).h := (x,y) -> 1/(x^2+y^2): a := 2: b := 3: del := 4: errortolerance := .1; mindeg := 2: degsteps := 10: bydeg :=4: lowx := a-del: highx := a+del: lowy := b-del: highy := b+del: lowz := -errortolerance: highz := errortolerance: xrange:= lowx..highx: yrange := lowy..highy: zrange := lowz..highz: framer3de := proc(i) local A, T1, deg: deg := mindeg + bydeg*i: A := plot3d( mtaylor(h(x,y),[x=a, y=b], deg)-h(x,y), x=lowx..highx, y=lowy..highy, view= lowz..highz, orientation=[135,45]): T1 := textplot3d([(highx+lowx)/2,lowy,highz, `Degree `||deg||` Taylor error`], align={BELOW,RIGHT}, font=[HELVETICA, BOLD, 12]): display3d({A,T1},axes=boxed); end: display([seq(framer3de(i), i=0..degsteps)], insequence = true, style=patch, view=lowz..highz);