(************** Content-type: application/mathematica ************** CreatedBy='Mathematica 5.2' 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[ 8549, 293]*) (*NotebookOutlinePosition[ 9252, 317]*) (* CellTagsIndexPosition[ 9208, 313]*) (*WindowFrame->Normal*) Notebook[{ Cell["Partial Derivatives, 3D Plots and Contour Plots", "Title"], Cell["\<\ Tuesday, October 3 Created by Jason Sherman\ \>", "Subsubtitle"], Cell["Recall that the command D[ ] is used for derivatives", "Text"], Cell[BoxData[ \(D[x^2, x]\)], "Input"], Cell[BoxData[ \(D[x^2, {x, 2}]\)], "Input"], Cell["Partial derivatives are equally as easy:", "Text"], Cell[BoxData[ \(D[x^2 - y^2 + x*y, x]\)], "Input"], Cell[BoxData[ \(D[x^2 - y^2 + x*y, y]\)], "Input"], Cell["Derivative wrt. x then wrt. y", "Text"], Cell[BoxData[ \(D[D[x^2 - y^2 + x*y, x], y]\)], "Input"], Cell[BoxData[ \(D[x^2 - y^2 + x*y, x, y]\)], "Input"], Cell["\<\ What about a gradient? \[Del]f = { \[PartialD]f / \[PartialD]x , \ \[PartialD]f / \[PartialD]y }. We can define \[Del]f(x,y) as a vector \ function of x and y... (we are a bit ahead of the class here)\ \>", "Text"], Cell[BoxData[{ \(f[x_, y_] = x^2 - y^2 - 2 x + 4 y + 6\), "\[IndentingNewLine]", \(gradf[x_, y_] = {\ D[f[x, y], x\ ]\ , \ D[f[x, y], y]\ }\)}], "Input"], Cell["Another way to get the gradient", "Text"], Cell[BoxData[ \(grdf[x_, y_]\ = \ D[f[x, y], {{x, y}}]\)], "Input"], Cell["The Jacobian, a matrix of partial second derivatives", "Text"], Cell[BoxData[ \(D[x^2 - y^2 + x*y, \ {{x, y}, 2}]\ // MatrixForm\)], "Input"], Cell["Plot3D", "Subsubsection"], Cell["\<\ Plot3D works just as you would expect if you've used the 2-D version, Plot.\ \>", "Text"], Cell[BoxData[ \(Plot3D[x^2 - y^2, {x, \(-3\), 3}, {y, \(-3\), 3}]\)], "Input"], Cell["Several helpful Options for Plot3D are shown below. ", "Text"], Cell[BoxData[ \(f[x_, y_] = Sqrt[x^2 + y^2]*Exp[\(-x^2\) - y^2]\)], "Input"], Cell[BoxData[ \(Plot3D[f[x, y], {x, \(-2.5\), 2.5}, {y, \(-2.5\), 2.5}]\)], "Input"], Cell["Label Axes in the same way you would a 2D plot.", "Text"], Cell[BoxData[ \(Plot3D[f[x, y], {x, \(-2.5\), 2.5}, {y, \(-2.5\), 2.5}, AxesLabel \[Rule] {"\", "\", "\"}]\)], \ "Input"], Cell["\<\ ViewPoint lets you change the angle from which you view the plot. You should \ try using the ViewPoint Selector found in the menu-bar under Input.\ \>", "Text"], Cell[BoxData[ \(Plot3D[f[x, y], {x, \(-2.5\), 2.5}, {y, \(-2.5\), 2.5}, ViewPoint \[Rule] {2, 0, 0.4}]\)], "Input"], Cell[BoxData[ \(Plot3D[f[x, y], {x, \(-2\), 2}, {y, \(-2\), 2}, ViewPoint \[Rule] { .2, .2, 2}]\)], "Input"], Cell["\<\ We can plot more points using PlotPoints->N, and we can turn the Mesh off by \ Mesh->False\ \>", "Text"], Cell[BoxData[ \(Plot3D[f[x, y], {x, \(-2.5\), 2.5}, {y, \(-2.5\), 2.5}, ViewPoint \[Rule] { .8, .8, 2}, PlotPoints \[Rule] 50]\)], "Input"], Cell[BoxData[ \(Plot3D[f[x, y], {x, \(-2.5\), 2.5}, {y, \(-2.5\), 2.5}, ViewPoint \[Rule] { .8, .8, 2}, PlotPoints \[Rule] 50, Mesh \[Rule] False]\)], "Input"], Cell["FaceGrids can sometimes help", "Text"], Cell[BoxData[ \(Plot3D[f[x, y], {x, \(-2.5\), 2.5}, {y, \(-2.5\), 2.5}, ViewPoint \[Rule] {1, 1, 1}, PlotPoints \[Rule] 100, Mesh \[Rule] False, FaceGrids \[Rule] All]\)], "Input"], Cell["You may want to turn the axes off", "Text"], Cell[BoxData[ \(Plot3D[f[x, y], {x, \(-2.5\), 2.5}, {y, \(-2.5\), 2.5}, ViewPoint \[Rule] {1, 1, 1}, PlotPoints \[Rule] 100, Mesh \[Rule] False, FaceGrids \[Rule] All, Axes \[Rule] False]\)], "Input"], Cell["\<\ Here are all the available options for Plot3D. Look some of them up if you \ like.\ \>", "Text"], Cell[BoxData[ \(Options[Plot3D]\)], "Input"], Cell["Contour Plots", "Subsubsection"], Cell["\<\ Again, contour plots work pretty much as you would expect. Here is an \ example.\ \>", "Text"], Cell[BoxData[ \(ContourPlot[f[x, y], {x, \(-2.5\), 2.5}, {y, \(-2.5\), 2.5}]\)], "Input"], Cell["We can increase the number of contours...", "Text"], Cell[BoxData[ \(ContourPlot[f[x, y], {x, \(-2.5\), 2.5}, {y, \(-2.5\), 2.5}, Contours \[Rule] 20]\)], "Input"], Cell["...and increase the resolution of the plot.", "Text"], Cell[BoxData[ \(ContourPlot[f[x, y], {x, \(-2.5\), 2.5}, {y, \(-2.5\), 2.5}, Contours \[Rule] 20, PlotPoints \[Rule] 100]\)], "Input"], Cell["\<\ We can also turn off the contour lines, making a neat looking picture. This \ is sometimes called a \"Density Plot\"\ \>", "Text"], Cell[BoxData[ \(p1 = ContourPlot[f[x, y], {x, \(-2.5\), 2.5}, {y, \(-2.5\), 2.5}, Contours \[Rule] 40, ContourLines \[Rule] False, PlotPoints \[Rule] 200]\)], "Input"], Cell[TextData[{ "Contour Plots don't have ", StyleBox["axes", FontSlant->"Italic"], ". They have a ", StyleBox["frame. ", FontSlant->"Italic"], "You can turn the axes and/or the frame on and off" }], "Text"], Cell[BoxData[ \(Show[p1, Frame \[Rule] False]\)], "Input"], Cell["\<\ This one has no frame, but it does have axes. See the difference?\ \>", "Text"], Cell[BoxData[ \(Show[p1, Frame \[Rule] False, Axes \[Rule] True]\)], "Input"], Cell["\<\ Just like you could label axes, you can label a frame. The option \ FrameLabel->{} lets you label the top, bottom, left, and right side of your \ graph.\ \>", "Text"], Cell[BoxData[ \(Show[p1, FrameLabel \[Rule] {"\", "\", "\", \ "\"}]\)], "Input"], Cell[BoxData[ \(Show[p1, FrameLabel \[Rule] {"\", "\", "\", "\"}, RotateLabel \[Rule] False]\)], "Input"], Cell["\<\ Note that 2D plots can have a frame instead of a label as well, it is just \ that by default, they have axes.\ \>", "Text"], Cell[BoxData[ \(Plot[x^2, {x, \(-2\), 2}, Axes \[Rule] False, Frame \[Rule] True, FrameLabel \[Rule] {"\", "\", "\", "\"}]\)], "Input"], Cell["Fun Stuff!", "Subsubsection"], Cell["Back to a 3D Plot.", "Text"], Cell[BoxData[ \(p1 = Plot3D[f[x, y], {x, \(-2.5\), 2.5}, {y, \(-2.5\), 2.5}, PlotPoints \[Rule] 100, Mesh \[Rule] False]\)], "Input"], Cell["\<\ Wouldn't it be nice to be able to rotate this without using ViewPoint? We \ can! We need to run a command first. It will effect all 3D plots in your \ notebook.\ \>", "Text"], Cell[BoxData[ \(<< RealTime3D`\)], "Input"], Cell[BoxData[ \(Show[p1]\)], "Input"], Cell[BoxData[ \(Plot3D[\(-x\)/Sqrt[x^2 + y^2], {x, \(-3\), 3}, {y, \(-3\), 3}, PlotPoints \[Rule] 50]\)], "Input"], Cell[BoxData[ \(Plot3D[\(-x\)/Sqrt[x^2 + y^2], {x, \(-3\), 3}, {y, \(-3\), 3}, PlotPoints \[Rule] 150, Mesh \[Rule] False]\)], "Input"], Cell["\<\ Notice how this is neat!, but it gets rid of axes labels... To get things \ back to normal, do:\ \>", "Text"], Cell[BoxData[ \(<< Default3D`\)], "Input"] }, FrontEndVersion->"5.2 for Microsoft Windows", ScreenRectangle->{{0, 1920}, {0, 1087}}, WindowSize->{1842, 1052}, WindowMargins->{{25, Automatic}, {Automatic, 0}}, ShowSelection->True, 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, 64, 0, 70, "Title"], Cell[1821, 53, 74, 3, 76, "Subsubtitle"], Cell[1898, 58, 68, 0, 55, "Text"], Cell[1969, 60, 42, 1, 65, "Input"], Cell[2014, 63, 47, 1, 65, "Input"], Cell[2064, 66, 56, 0, 55, "Text"], Cell[2123, 68, 54, 1, 65, "Input"], Cell[2180, 71, 54, 1, 65, "Input"], Cell[2237, 74, 45, 0, 55, "Text"], Cell[2285, 76, 60, 1, 65, "Input"], Cell[2348, 79, 57, 1, 65, "Input"], Cell[2408, 82, 230, 4, 100, "Text"], Cell[2641, 88, 164, 2, 116, "Input"], Cell[2808, 92, 47, 0, 55, "Text"], Cell[2858, 94, 72, 1, 65, "Input"], Cell[2933, 97, 68, 0, 55, "Text"], Cell[3004, 99, 82, 1, 65, "Input"], Cell[3089, 102, 31, 0, 44, "Subsubsection"], Cell[3123, 104, 99, 2, 55, "Text"], Cell[3225, 108, 82, 1, 65, "Input"], Cell[3310, 111, 68, 0, 55, "Text"], Cell[3381, 113, 80, 1, 65, "Input"], Cell[3464, 116, 88, 1, 65, "Input"], Cell[3555, 119, 63, 0, 55, "Text"], Cell[3621, 121, 159, 3, 116, "Input"], Cell[3783, 126, 171, 3, 100, "Text"], Cell[3957, 131, 126, 2, 65, "Input"], Cell[4086, 135, 120, 2, 65, "Input"], Cell[4209, 139, 114, 3, 55, "Text"], Cell[4326, 144, 151, 2, 116, "Input"], Cell[4480, 148, 178, 3, 116, "Input"], Cell[4661, 153, 44, 0, 55, "Text"], Cell[4708, 155, 198, 3, 116, "Input"], Cell[4909, 160, 49, 0, 55, "Text"], Cell[4961, 162, 225, 4, 116, "Input"], Cell[5189, 168, 107, 3, 55, "Text"], Cell[5299, 173, 48, 1, 65, "Input"], Cell[5350, 176, 38, 0, 44, "Subsubsection"], Cell[5391, 178, 105, 3, 55, "Text"], Cell[5499, 183, 93, 1, 65, "Input"], Cell[5595, 186, 57, 0, 55, "Text"], Cell[5655, 188, 121, 2, 65, "Input"], Cell[5779, 192, 59, 0, 55, "Text"], Cell[5841, 194, 145, 2, 116, "Input"], Cell[5989, 198, 141, 3, 55, "Text"], Cell[6133, 203, 196, 4, 116, "Input"], Cell[6332, 209, 227, 8, 55, "Text"], Cell[6562, 219, 62, 1, 65, "Input"], Cell[6627, 222, 90, 2, 55, "Text"], Cell[6720, 226, 81, 1, 65, "Input"], Cell[6804, 229, 177, 4, 100, "Text"], Cell[6984, 235, 121, 3, 65, "Input"], Cell[7108, 240, 153, 3, 65, "Input"], Cell[7264, 245, 133, 3, 55, "Text"], Cell[7400, 250, 183, 3, 116, "Input"], Cell[7586, 255, 35, 0, 44, "Subsubsection"], Cell[7624, 257, 34, 0, 55, "Text"], Cell[7661, 259, 153, 3, 65, "Input"], Cell[7817, 264, 186, 5, 112, "Text"], Cell[8006, 271, 47, 1, 65, "Input"], Cell[8056, 274, 41, 1, 65, "Input"], Cell[8100, 277, 125, 2, 65, "Input"], Cell[8228, 281, 146, 2, 116, "Input"], Cell[8377, 285, 119, 3, 55, "Text"], Cell[8499, 290, 46, 1, 65, "Input"] } ] *) (******************************************************************* End of Mathematica Notebook file. *******************************************************************)