(*********************************************************************** Mathematica-Compatible Notebook This notebook can be used on any computer system with Mathematica 4.0, MathReader 4.0, or any compatible application. The data for the notebook starts with the line containing stars above. To get the notebook into a Mathematica-compatible application, do one of the following: * Save the data starting with the line of stars above into a file with a name ending in .nb, then open the file inside the application; * Copy the data starting with the line of stars above to the clipboard, then use the Paste menu command inside the application. Data for notebooks contains only printable 7-bit ASCII and can be sent directly in email or through ftp in text mode. Newlines can be CR, LF or CRLF (Unix, Macintosh or MS-DOS style). NOTE: If you modify the data for this notebook not in a Mathematica- compatible application, you must delete the line below containing the word CacheID, otherwise Mathematica-compatible applications may try to use invalid cache data. For more information on notebooks and Mathematica-compatible applications, contact Wolfram Research: web: http://www.wolfram.com email: info@wolfram.com phone: +1-217-398-0700 (U.S.) Notebook reader applications are available free of charge from Wolfram Research. ***********************************************************************) (*CacheID: 232*) (*NotebookFileLineBreakTest NotebookFileLineBreakTest*) (*NotebookOptionsPosition[ 8569, 237]*) (*NotebookOutlinePosition[ 9277, 262]*) (* CellTagsIndexPosition[ 9233, 258]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell["Taylor Polynomials", "Title", CellFrame->True, TextAlignment->Center, Background->RGBColor[0, 1, 0]], Cell["\<\ This notebook is by Steven Amgott. Please send any questions or comments to \ samgott1@swarthmore.edu. Feel free to use and distribute this notebook, but \ keep this author information in any copy you use or distribute.\ \>", "SmallText"], Cell[TextData[{ "In the sections below, anything in ", StyleBox["magenta", FontColor->RGBColor[1, 0, 1]], " is something you can, and possibly should, change. The two ", StyleBox["Off", FontColor->RGBColor[1, 0, 0]], " commands prevent a few annoying warning messages." }], "Text"], Cell[BoxData[{ \(\(Off[General::"\"];\)\), "\n", \(\(Off[General::"\"];\)\)}], "Input", InitializationCell->True], Cell[CellGroupData[{ Cell["Finding the Linear and Quadratic polynomials", "Section"], Cell["\<\ The cell below finds the first and second order partial derivatives of f(x,y) \ at the point (a,b), and then constructs the linear (l[x,y]) and quadratic \ (q[x,y]) Taylor polynomials for the function centered at (a,b).\ \>", "Text"], Cell[BoxData[{\(Clear[f, x, y, a, b, fx, fy, fxx, fyy, fxy, l, q]\), "\n", RowBox[{\(f[x_, y_]\), ":=", StyleBox[\(Cos[2 x + y] + 3 Sin[x + y]\), FontColor->RGBColor[1, 0, 1]]}], "\n", RowBox[{ RowBox[{"a", "=", StyleBox["0", FontColor->RGBColor[1, 0, 1]]}], ";"}], "\n", RowBox[{ RowBox[{"b", "=", StyleBox["0", FontColor->RGBColor[1, 0, 1]]}], ";"}], "\n", \(fx = \[PartialD]\_x\ f[x, y] /. {x -> a, y -> b}\), "\n", \(fy = \[PartialD]\_y\ f[x, y] /. {x -> a, y -> b}\), "\n", \(fxx = \[PartialD]\_{x, 2}\ f[x, y] /. {x -> a, y -> b}\), "\n", \(fyy = \[PartialD]\_{y, 2}\ f[x, y] /. {x -> a, y -> b}\), "\n", \(fxy = \[PartialD]\_\(x, y\)\ f[x, y] /. {x -> a, y -> b}\), "\n", \(l[x_, y_] = f[a, b] + fx\ \((x - a)\) + fy \((y - b)\)\), "\n", \(q[x_, y_] = f[a, b] + fx\ \((x - a)\) + fy \((y - b)\) + \(fxx\/2\) \((x - a)\)\^2 + fxy \((x - a)\) \((y - b)\) + \(fyy\/2\) \((y - b)\)\^2\)}], "Input"] }, Closed]], Cell[CellGroupData[{ Cell["3D plots", "Section"], Cell[TextData[{ "The cell below produces plots of the function, the linear approximation, \ and the quadratic approximation on a rectangle whose center is (a,b). Make \ sure you have evaluated the cell in the first section defining the linear and \ quadratic approximations before evaluating this one. You can \"zoom-in\" by \ changing the value of ", StyleBox["h", FontColor->RGBColor[1, 0, 1]], " (and/or ", StyleBox["k", FontColor->RGBColor[1, 0, 1]], ") and re-evaluating the cell." }], "Text"], Cell[BoxData[{\(Clear[h, k]\), "\n", RowBox[{ RowBox[{"h", "=", StyleBox["2", FontColor->RGBColor[1, 0, 1]]}], ";"}], "\n", RowBox[{ RowBox[{"k", "=", StyleBox["h", FontColor->RGBColor[1, 0, 1]]}], ";"}], "\n", \(Plot3D[f[x, y], {x, a - h, a + h}, {y, b - k, b + k}, PlotLabel \[Rule] "\"];\), "\n", \(Plot3D[ l[x, y], {x, a - h, a + h}, {y, b - k, b + k}, PlotLabel \[Rule] "\"];\), "\n", \(Plot3D[ q[x, y], {x, a - h, a + h}, {y, b - k, b + k}, PlotLabel \[Rule] "\"];\)}], "Input"], Cell[TextData[{ "These plots may not be the best to see how decreasing ", StyleBox["h", FontColor->RGBColor[1, 0, 1]], " improves the approximations. It might be better to look at the contour \ plots, which is done in the next section." }], "Text"] }, Closed]], Cell[CellGroupData[{ Cell["Contour plots", "Section"], Cell[TextData[{ "The next cell produces contour plots of the function, the ", StyleBox["linear approximation", FontColor->RGBColor[1, 0, 0]], ", and the ", StyleBox["quadratic approximation", FontColor->RGBColor[0, 1, 0]], " on a rectangle whose center is (a,b). Make sure you have evaluated the \ cell in the first section defining the linear and quadratic approximations \ before evaluating this one." }], "Text"], Cell[BoxData[{\(Clear[h, k, plotf, plotl, plotq]\), "\n", RowBox[{ RowBox[{"h", "=", StyleBox["1", FontColor->RGBColor[1, 0, 1]]}], ";"}], "\n", RowBox[{ RowBox[{"k", "=", StyleBox["h", FontColor->RGBColor[1, 0, 1]]}], ";"}], "\n", \(plotf = ContourPlot[f[x, y], {x, a - h, a + h}, {y, b - k, b + k}, ContourShading \[Rule] False];\), "\n", \(plotl = ContourPlot[l[x, y], {x, a - h, a + h}, {y, b - k, b + k}, ContourShading \[Rule] False, ContourStyle \[Rule] RGBColor[1, 0, 0]];\), "\n", \(plotq = ContourPlot[q[x, y], {x, a - h, a + h}, {y, b - k, b + k}, ContourShading \[Rule] False, ContourStyle \[Rule] RGBColor[0, 1, 0]];\)}], "Input"], Cell[TextData[{ "The next cell superimposes the contours of the function and the linear \ approximation in the first plot, the function and the quadratic approximation \ in the second plot, and all three together in the third plot. To zoom in, \ change ", StyleBox["h", FontColor->RGBColor[1, 0, 1]], " (and/or ", StyleBox["k", FontColor->RGBColor[1, 0, 1]], ") in the cell above, re-evaluate it, and then re-evaluate the cell below." }], "Text"], Cell[BoxData[{ \(\(Show[plotf, plotl];\)\), "\n", \(\(Show[plotf, plotq];\)\), "\n", \(\(Show[plotf, plotl, plotq];\)\)}], "Input"] }, Closed]], Cell[CellGroupData[{ Cell["Tables of values and errors", "Section"], Cell["\<\ The cell below produces a table of values of the function and the \ approximations, and computes the errors in the approximations as we get \ closer to the point (a,b). Make sure you have evaluated the cell in the \ first section defining the linear and quadratic approximations before \ evaluating this one. What are the factors by which the errors in the linear \ and quadratic approximations decrease as the distance we are from the center \ point decreases by a factor of 10?\ \>", "Text"], Cell[BoxData[ \(TableForm[ N[Table[{10\^\(-n\), f[a + 10\^\(-n\), b + 10\^\(-n\)], l[a + 10\^\(-n\), b + 10\^\(-n\)], l[a + 10\^\(-n\), b + 10\^\(-n\)] - f[a + 10\^\(-n\), b + 10\^\(-n\)], q[a + 10\^\(-n\), b + 10\^\(-n\)], q[a + 10\^\(-n\), b + 10\^\(-n\)] - f[a + 10\^\(-n\), b + 10\^\(-n\)]}, {n, 0, 6}]], TableHeadings \[Rule] {{}, {"\", "\", \ "\", "\", "\", "\"}}]\)], "Input"] }, Closed]] }, Open ]] }, FrontEndVersion->"4.0 for Microsoft Windows", ScreenRectangle->{{0, 1024}, {0, 720}}, AutoGeneratedPackage->None, WindowToolbars->"EditBar", WindowSize->{748, 664}, WindowMargins->{{0, Automatic}, {Automatic, 0}} ] (*********************************************************************** Cached data follows. If you edit this Notebook file directly, not using Mathematica, you must remove the line containing CacheID at the top of the file. The cache data will then be recreated when you save this file from within Mathematica. ***********************************************************************) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[1739, 51, 112, 3, 121, "Title"], Cell[1854, 56, 250, 4, 44, "SmallText"], Cell[2107, 62, 300, 8, 52, "Text"], Cell[2410, 72, 141, 3, 50, "Input", InitializationCell->True], Cell[CellGroupData[{ Cell[2576, 79, 63, 0, 53, "Section"], Cell[2642, 81, 243, 4, 52, "Text"], Cell[2888, 87, 1077, 21, 243, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[4002, 113, 27, 0, 33, "Section"], Cell[4032, 115, 518, 12, 71, "Text"], Cell[4553, 129, 654, 14, 130, "Input"], Cell[5210, 145, 259, 6, 52, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[5506, 156, 32, 0, 33, "Section"], Cell[5541, 158, 434, 10, 52, "Text"], Cell[5978, 170, 792, 17, 170, "Input"], Cell[6773, 189, 465, 11, 71, "Text"], Cell[7241, 202, 145, 3, 70, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[7423, 210, 46, 0, 33, "Section"], Cell[7472, 212, 506, 8, 90, "Text"], Cell[7981, 222, 560, 11, 130, "Input"] }, Closed]] }, Open ]] } ] *) (*********************************************************************** End of Mathematica Notebook file. ***********************************************************************)