(************** Content-type: application/mathematica ************** CreatedBy='Mathematica 5.0' Mathematica-Compatible Notebook This notebook can be used with any Mathematica-compatible application, such as Mathematica, MathReader or Publicon. 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[ 12258, 365]*) (*NotebookOutlinePosition[ 12986, 390]*) (* CellTagsIndexPosition[ 12942, 386]*) (*WindowFrame->Normal*) Notebook[{ Cell["Contour Plots and Animations", "Title", Background->RGBColor[0, 0, 1]], Cell["Math 233\tFall 2002", "Subtitle"], Cell[CellGroupData[{ Cell["\<\ Initialization Cells \ \>", "Subsubsection"], Cell[BoxData[{ \( (*\(:\)\(Title : \ Surface - to - Contour\ Map\ Animation\)\ *) \n\n (*\(:\)\(Context : \ Graphics`ContourAnimate`\)\ *) \n\n (*\(:\)\(Author : \ Bradford\ J . \ Kline\)\ *) \n\n (*\(:\)\(Mathematica\ \(Version : \ 3.0\)\)\ *) \n\n (*\(:\)\(Package\ \(Version : \ 1.1\)\)\ *) \n\n (*\(\(:\)\(History : \n\t V1 .0\ by\ B . \ Kline\)\), \ March\ 1999. \ \ \n\tV1 .1\ by\ B . \ Kline, \ June\ 1999. \ \ *) \n\n (*\ Last\ \(Revision : \ \ June\ 1999\)\ *) \n\n\(Off[ General::"\"];\)\), "\n", \(\(\(Off[General::"\"];\)\(\n\) \)\), "\n", \(\(\(BeginPackage["\"];\)\(\n\) \)\), "\n", \(\(\(Needs["\"]\)\(\n\) \)\), "\n", \(\(ContourAnimate::usage = "\";\)\n\t\t\), \ "\n", \(\(\(Begin["\<`Private`\>"];\)\(\n\) \)\), "\n", \(\(\(ContourAnimate[f_, \ {x_, x0_, x1_}, \ {y_, y0_, y1_}, numberofframes_Integer, \ opts___] := \n\t Module[{contours, surface, contours3d, g, a, val, pts, originalview, targetview, plotrange, fullrange, t}, \n contours = ContourPlot[f, {x, x0, x1}, {y, y0, y1}, ContourShading -> False, DisplayFunction -> Identity, Evaluate[FilterOptions[ContourPlot, opts]]]; \n surface = Plot3D[f, {x, x0, x1}, {y, y0, y1}, \ DisplayFunction -> Identity, Evaluate[FilterOptions[Plot3D, opts]], Mesh -> False]; \n plotrange = FullOptions[surface, PlotRange]; \n fullrange = {plotrange[\([1]\)], plotrange[\([2]\)], 1/2 {plotrange[\([3, 1]\)] - Abs[plotrange[\([3, 1]\)]], plotrange[\([3, 2]\)] + Abs[plotrange[\([3, 2]\)]]}}; \n Do[\n\tClear[g]; \ng\ = \ Function[{x, y}, a*f]; \n\t contours3d = \(Graphics[contours]\)[\([1]\)] /. Line[pts_] :> \((val = Apply[g, First[pts]]; Line[Map[Append[#, val] &, pts]])\); \n Show[Graphics3D[contours3d], surface, DisplayFunction -> $DisplayFunction, FilterOptions[Graphics3D, opts], \n\t\t\tPlotRange -> fullrange], {a, 1, 0, N[\(-1\)/\((numberofframes)\)]}]; \n originalview = FullOptions[surface, ViewPoint]; \n targetview\ = \ {0, 3, 30}; \n\t\tDo[\n\t\t\tShow[ Graphics3D[contours3d], DisplayFunction -> $DisplayFunction, ViewPoint -> \((\((1 - t)\)*originalview + \((t)\)*targetview)\), FilterOptions[Graphics3D, opts], PlotRange -> fullrange], {t, 0, 1, .1}]\n\t\t\t\t]\)\(\n\) \)\), "\n", \(\(\(ContourAnimate[f_, \ xRange_List, \ yRange_List, \ opts___Rule] := ContourAnimate[f, \ xRange, \ yRange, \ 10, \ opts]\)\(\n\) \)\), "\n", \(\(\(End[\ ];\)\(\n\) \)\), "\n", \(EndPackage[\ ]\)}], "Input", InitializationCell->True] }, Closed]], Cell["\<\ The initialization cells in this notebook define the command ContourAnimate. \ This command allows us to illustrate the relationship between horizontal \ traces of the surface z = f[x,y] and the contour diagram of the function \ f[x,y]. The command generates a sequence of plots showing the traces \ migrating from the surface to the xy-plane.\ \>", "Text"], Cell[CellGroupData[{ Cell["ContourAnimate", "Section"], Cell["\<\ Evaluate the following for a brief description of the syntax for \ ContourAnimate:\ \>", "Text"], Cell[BoxData[ \(\(?ContourAnimate\)\)], "Input"], Cell[TextData[{ "ContourAnimate", " basically accepts the same arguments as the standard ", StyleBox["Mathematica", FontSlant->"Italic"], " function Plot3D. Here is an example:" }], "Text"], Cell[BoxData[ \(\(ContourAnimate[x^2 + y^2, {x, \(-5\), 5}, {y, \(-5\), 5}, 30];\)\)], "Input"], Cell["\<\ ContourAnimate accepts an optional parameter following the second range. \ This parameter specifies the number of frames before the contours reach the \ xy-plane. The default number of frames is 10. Here is an example with 4 \ frames:\ \>", "Text"], Cell[BoxData[ \(\(ContourAnimate[x^2 + y^2, {x, \(-5\), 5}, {y, \(-5\), 5}, 4];\)\)], "Input"], Cell["\<\ We may enter the same options that Plot3D and Graphics3D permit, including a \ change of ViewPoint and PlotRange.\ \>", "Text"], Cell[BoxData[ \(\(\(\ \)\(ContourAnimate[x^2 + y^2, {x, \(-5\), 5}, {y, \(-5\), 5}, 20, ViewPoint -> {0.568, \ \(-1.288\), \ \(-1.495\)}, PlotRange -> {0, 25}, ClipFill -> None];\)\)\)], "Input"], Cell["\<\ Here is a simulated mountain scene. You can use the ContourAnimate command \ to demonstrate the relationship between the earth's terrain and the \ corresponding topographic map.\ \>", "Text"], Cell[BoxData[ \(\(ContourAnimate[ Sin[x]\ Sin[y]\ - 5, {x, \(-2\) Pi, 2 Pi}, {y, \(-2\) Pi, 2 Pi}, 15, PlotPoints -> 30];\)\)], "Input", AnimationDisplayTime->0.2197] }, Closed]], Cell[CellGroupData[{ Cell["Shadow Plots", "Section"], Cell["\<\ Shadow Plots are an interesting way to see both an elevation and contour at the same time. You must load the package below to enable you to output the graphic.\ \>", "Text", Evaluatable->False], Cell["\<\ Needs[\"Graphics`Graphics3D`\"] ?ShadowPlot3D\ \>", "Input", PageWidth->Infinity, FontFamily->"Courier New", FontSize->12, FontWeight->"Bold", FontColor->GrayLevel[0], Background->GrayLevel[1]], Cell["\<\ Clear[f] f[x_,y_]:=Exp[-(x^2+y^2)] ShadowPlot3D[f[x,y],{x,-2,2},{y,-2,2}, \tShadowPosition->1, \tShadowMesh->False, \tPlotPoints->20, \tViewPoint->{1.420,-2.776,1.315}];\ \>", "Input", PageWidth->Infinity, FontFamily->"Courier New", FontSize->12, FontWeight->"Bold", FontColor->GrayLevel[0], Background->GrayLevel[1]] }, Closed]], Cell[CellGroupData[{ Cell["Contour Plot", "Section"], Cell["\<\ Clear[f] f[x_,y_]:=2-x-y^2 ContourPlot[f[x,y],{x,-5,5},{y,-5,5}, \tColorFunction->Hue];\ \>", "Input", PageWidth->Infinity, FontFamily->"Courier New", FontSize->12, FontWeight->"Bold", FontColor->GrayLevel[0], Background->GrayLevel[1]] }, Closed]], Cell[CellGroupData[{ Cell["CPLabel", "Section"], Cell[BoxData[ \(\(General[Spell1[Off]];\)\)], "Input"], Cell[BoxData[ \(CPLabel[f_, xlimit_, \ ylimit_, \ xclabl_, \ yclabl_, \ opts___] := \n\t CompoundExpression[\ Clear[p1c, p1t], \n\t\tp1c = ContourPlot[f, xlimit, ylimit, opts, ContourShading -> False, DisplayFunction -> Identity], \ p1t = Table[Text[N[f, 2], {xlimit[\([1]\)], ylimit[\([1]\)]}], xclabl, yclabl], \n\t\tShow[{p1c, Graphics[p1t]}, \ DisplayFunction -> $DisplayFunction]]\)], "Input"], Cell[BoxData[ \(\(f[x_, y_] = x^2 + y^2;\)\)], "Input"], Cell[BoxData[ \(\(CPLabel[ f[x, y], {x, \(-2\), 2}, {y, \(-2\), 2}, {x, \(-2\), 2, .5}, {y, \(-2\), 2, .5}, Axes -> True, AxesLabel -> {"\", "\"}];\)\)], "Input"] }, Closed]], Cell[CellGroupData[{ Cell["All of them:", "Subsubsection"], Cell[BoxData[ \(f[x_, y_] = Cos[x]\ Cos[y]\ Exp[\(-Sqrt[x^2 + y^2]\)/4]\)], "Input"], Cell[BoxData[ \(\(ContourAnimate[f[x, y], {x, \(-Pi\), Pi}, {y, \(-Pi\), Pi}, 10, ViewPoint \[Rule] {1.420, \(-2.776\), 1.315}];\)\)], "Input"], Cell[BoxData[ \(\(ShadowPlot3D[f[x, y], {x, \(-Pi\), Pi}, {y, \(-Pi\), Pi}, ShadowPosition \[Rule] 1, ShadowMesh \[Rule] False, PlotPoints \[Rule] 40, ViewPoint \[Rule] {1.420, \(-2.776\), 1.315}];\)\)], "Input"], Cell[BoxData[ \(\(ContourPlot[f[x, y], {x, \(-Pi\), Pi}, {y, \(-Pi\), Pi}, ColorFunction \[Rule] Hue, Axes -> True, AxesLabel -> {"\", "\"}];\)\)], "Input"], Cell[BoxData[ \(\(CPLabel[ f[x, y], {x, \(-Pi\), Pi}, {y, \(-Pi\), Pi}, {x, \(-Pi\), Pi, 0.5 Pi}, {y, \(-Pi\), Pi, Pi/2}, Axes -> True, AxesLabel -> {"\", "\"}];\)\)], "Input"], Cell["Some examples:", "Text"], Cell[BoxData[ \(\(ContourPlot[Sin[x], {x, 0, 2 Pi}, \ {y, 0, 2 Pi}, \ ContourShading -> False, \ Contours -> 20, Frame -> False\ ];\)\)], "Input"], Cell[BoxData[ \(\(Plot3D[Sin[x], {x, 0, 2 Pi}, \ {y, 0, 2 Pi}, \ Boxed -> False, \ Axes -> False];\)\)], "Input"], Cell[BoxData[ \(\(ContourPlot[x\ y, {x, \(-5\), 5}, \ {y, \(-5\), 5}, \ ContourShading -> False, \ Contours -> 20, Frame -> False\ ];\)\)], "Input"], Cell[BoxData[ \(\(Plot3D[x\ y, {x, \(-100\), 100}, \ {y, \(-100\), 100}, Boxed -> False, \ Axes -> False, \ PlotPoints -> 25];\)\)], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(\(ContourPlot[1 - 2 x\ - y, {x, \(-5\), 5}, \ {y, \(-5\), 5}, \ ContourShading -> False, \ Contours -> 20, Frame -> False\ ];\)\)], "Input"], Cell[BoxData[ \(\(Plot3D[1 - 2 x\ - y, {x, \(-5\), 5}, \ {y, \(-5\), 5}, Boxed -> False, \ Axes -> False, \ PlotPoints -> 25];\)\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(ContourPlot[x^2 + 4 y^2, {x, \(-5\), 5}, \ {y, \(-5\), 5}, \ ContourShading -> False, \ Contours -> 20, Frame -> False, \ PlotPoints -> 50]\)], "Input"], Cell[BoxData[ \(\(Plot3D[x^2 + 4 y^2, {x, \(-10\), 10}, \ {y, \(-5\), 5}, Boxed -> False, \ Axes -> False, PlotPoints -> 25];\)\)], "Input"] }, Open ]], Cell[BoxData[ \(\(ContourPlot[ Exp[\(-\((x^2\ + \ y^2)\)\)], {x, \(-5\), 5}, \ {y, \(-5\), 5}, \ ContourShading -> False, \ Contours -> 20, Frame -> False, PlotPoints -> 50];\)\)], "Input"], Cell[BoxData[ \(\(Plot3D[ Exp[\(-\((x^2\ + \ y^2)\)\)], {x, \(-10\), 10}, \ {y, \(-5\), 5}, Boxed -> False, \ Axes -> False, PlotPoints \[Rule] 25, \ PlotRange \[Rule] All];\)\)], "Input"] }, Closed]] }, FrontEndVersion->"5.0 for Microsoft Windows", ScreenRectangle->{{0, 1024}, {0, 677}}, AutoGeneratedPackage->None, CellGrouping->Manual, WindowSize->{792, 528}, WindowMargins->{{0, Automatic}, {Automatic, 0}}, StyleDefinitions -> "DemoText.nb" ] (******************************************************************* 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[1754, 51, 78, 1, 70, "Title"], Cell[1835, 54, 39, 0, 41, "Subtitle"], Cell[CellGroupData[{ Cell[1899, 58, 54, 3, 71, "Subsubsection"], Cell[1956, 63, 3346, 64, 1300, "Input", InitializationCell->True] }, Closed]], Cell[5317, 130, 369, 6, 66, "Text"], Cell[CellGroupData[{ Cell[5711, 140, 33, 0, 54, "Section"], Cell[5747, 142, 106, 3, 29, "Text"], Cell[5856, 147, 52, 1, 40, "Input"], Cell[5911, 150, 202, 6, 29, "Text"], Cell[6116, 158, 108, 2, 40, "Input"], Cell[6227, 162, 261, 5, 48, "Text"], Cell[6491, 169, 107, 2, 40, "Input"], Cell[6601, 173, 137, 3, 28, "Text"], Cell[6741, 178, 217, 3, 60, "Input"], Cell[6961, 183, 202, 4, 48, "Text"], Cell[7166, 189, 192, 4, 40, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[7395, 198, 31, 0, 34, "Section"], Cell[7429, 200, 207, 5, 91, "Text", Evaluatable->False], Cell[7639, 207, 215, 9, 58, "Input"], Cell[7857, 218, 339, 14, 148, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[8233, 237, 31, 0, 34, "Section"], Cell[8267, 239, 257, 11, 94, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[8561, 255, 26, 0, 34, "Section"], Cell[8590, 257, 58, 1, 40, "Input"], Cell[8651, 260, 474, 8, 140, "Input"], Cell[9128, 270, 59, 1, 40, "Input"], Cell[9190, 273, 204, 4, 60, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[9431, 282, 37, 0, 28, "Subsubsection"], Cell[9471, 284, 88, 1, 40, "Input"], Cell[9562, 287, 156, 2, 40, "Input"], Cell[9721, 291, 243, 4, 60, "Input"], Cell[9967, 297, 186, 3, 60, "Input"], Cell[10156, 302, 217, 4, 60, "Input"], Cell[10376, 308, 30, 0, 29, "Text"], Cell[10409, 310, 170, 3, 60, "Input"], Cell[10582, 315, 128, 2, 40, "Input"], Cell[10713, 319, 170, 3, 40, "Input"], Cell[10886, 324, 154, 2, 40, "Input"], Cell[CellGroupData[{ Cell[11065, 330, 180, 3, 60, "Input"], Cell[11248, 335, 156, 2, 40, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[11441, 342, 187, 3, 60, "Input"], Cell[11631, 347, 154, 2, 40, "Input"] }, Open ]], Cell[11800, 352, 220, 4, 60, "Input"], Cell[12023, 358, 219, 4, 60, "Input"] }, Closed]] } ] *) (******************************************************************* End of Mathematica Notebook file. *******************************************************************)