(************** 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[ 29407, 769]*) (*NotebookOutlinePosition[ 30105, 793]*) (* CellTagsIndexPosition[ 30061, 789]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell["Directional Derivatives", "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 general, anything in ", StyleBox["magenta", FontColor->RGBColor[1, 0, 1]], " in the input cells is something you can, and possibly should, change. \ Any ", StyleBox["magenta", FontColor->RGBColor[1, 0, 1]], " in the text cells is possibly something you need to do." }], "Text"], Cell[CellGroupData[{ Cell["\<\ Initialization. (Can be skipped, if you answer \"Yes\" to the initialization \ request.)\ \>", "Section"], Cell[CellGroupData[{ Cell["Eliminating some unnecessary warning messages.", "Subsection"], Cell[BoxData[{ \(\(Off[General::"\"];\)\), "\n", \(\(Off[General::"\"];\)\)}], "Input", InitializationCell->True] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["A visualization of directional derivatives", "Section"], Cell[TextData[{ "The first input cell shows a picture that can help you visualize what a \ directional derivative means. You give a function ", StyleBox["f[x,y]", FontColor->RGBColor[1, 0, 1]], ", bounds on x and y, a point ", StyleBox["{x0,y0}", FontColor->RGBColor[1, 0, 1]], " where you want to find a directional derivative, and a vector ", StyleBox["{u,v}", FontColor->RGBColor[1, 0, 1]], " which is then normalized (i.e. replaced with the unit vector ", Cell[BoxData[ FormBox[ FractionBox[ RowBox[{"{", RowBox[{ StyleBox["u", FontSlant->"Plain"], ",", StyleBox["v", FontSlant->"Plain"]}], "}"}], RowBox[{"|", RowBox[{"{", RowBox[{ StyleBox["u", FontSlant->"Plain"], ",", StyleBox["v", FontSlant->"Plain"]}], "}"}], "|"}]], TraditionalForm]]], ") to give the direction in which you want to find the rate of change \ (directional derivative). The point and vector are used to create a vertical \ plane. The intersection of that plane and the surface gives a curve whose \ slope at the point ", StyleBox["{x0,y0} ", FontColor->RGBColor[1, 0, 1]], "is the directional derivative. (You have to think of the positive \ direction for the curve being in the direction of ", StyleBox["{u,v}", FontColor->RGBColor[1, 0, 1]], ".) The output consists of the value of the directional derivative \ computed as the derivative of the one-variable function ", StyleBox["f[x0 + t u, y0 + t v]", FontColor->RGBColor[1, 0, 1]], " with respect to t, at t = 0 (after ", StyleBox["{u,v}", FontColor->RGBColor[1, 0, 1]], "has been normalized, of course) with two graphs. The first graph is of \ the surface and the intersecting plane, while the second is a two-dimensional \ plot of the cross section curve (with positive t in this graph corresponding \ to going in the direction ", StyleBox["{u,v}", FontColor->RGBColor[1, 0, 1]], "on the first graph) together with a plot of the tangent line to the curve \ (in ", StyleBox["red", FontColor->RGBColor[1, 0, 0]], "). Remember the slope of this tangent line is the directional derivative \ we have calculated.\n\n", StyleBox["One important note about any of the input cells below", FontColor->RGBColor[0, 0, 1]], ": you don't need to understand, or even read, any of the code (especially \ the complicated graphics code) in order to go through this notebook. I do \ point out with comments (in ", StyleBox["blue", FontColor->RGBColor[0, 0, 1]], ") where some of the calculations are being done. The code is there in \ case you want to see how ", StyleBox["Mathematica", FontSlant->"Italic"], " ticks, and to function as an example of how to get things done if you \ later use ", StyleBox["Mathematica", FontSlant->"Italic"], " for other problems. The only things you may need to change are those in \ ", StyleBox["magenta", FontColor->RGBColor[1, 0, 1]], "; the rest you should leave alone. ", StyleBox["Evaluate the next cell to see the plots. ", FontColor->RGBColor[1, 0, 1]] }], "Text", FontSize->14], Cell[BoxData[{\(Clear[f, x, y, xmin, xmax, ymin, ymax, x0, y0, u, v, m, t, surfPlot, intPlot, \ crossPlot]\), "\[IndentingNewLine]", RowBox[{\(f[x_, y_]\), ":=", StyleBox[\(3 x + 12 y - x\^3 - y\^3\), FontColor->RGBColor[1, 0, 1]]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"xmin", "=", StyleBox[\(-2\), FontColor->RGBColor[1, 0, 1]]}], ";"}], "\n", RowBox[{ RowBox[{"xmax", "=", StyleBox["2", FontColor->RGBColor[1, 0, 1]]}], ";"}], "\n", RowBox[{ RowBox[{"ymin", "=", StyleBox[\(-3\), FontColor->RGBColor[1, 0, 1]]}], ";"}], "\n", RowBox[{ RowBox[{ RowBox[{"ymax", "=", StyleBox["3", FontColor->RGBColor[1, 0, 1]]}], ";"}], "\t\t"}], "\n", RowBox[{ RowBox[{"surfPlot", "=", RowBox[{"Plot3D", "[", RowBox[{\(f[x, y]\), ",", RowBox[{"{", RowBox[{"x", StyleBox[",", FontColor->GrayLevel[0]], "xmin", ",", "xmax"}], "}"}], ",", RowBox[{"{", RowBox[{"y", StyleBox[",", FontColor->GrayLevel[0]], "ymin", ",", "ymax"}], "}"}], ",", \(DisplayFunction \[Rule] Identity\)}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ StyleBox[\({x0, y0}\), FontColor->GrayLevel[0]], StyleBox["=", FontColor->GrayLevel[0]], RowBox[{ StyleBox["{", FontColor->GrayLevel[0]], RowBox[{ StyleBox[ FractionBox[ StyleBox["1", FontColor->RGBColor[1, 0, 1]], "2"], FontColor->RGBColor[1, 0, 1]], StyleBox[",", FontColor->GrayLevel[0]], StyleBox[ FractionBox[ StyleBox["1", FontColor->RGBColor[1, 0, 1]], "2"], FontColor->RGBColor[1, 0, 1]]}], "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"{", StyleBox[\(u, v\), FontColor->GrayLevel[0]], StyleBox["}", FontColor->GrayLevel[0]]}], StyleBox["=", FontColor->GrayLevel[0]], RowBox[{ StyleBox["{", FontColor->GrayLevel[0]], RowBox[{ StyleBox["3", FontColor->RGBColor[1, 0, 1]], StyleBox[",", FontColor->GrayLevel[0]], StyleBox["2", FontColor->RGBColor[1, 0, 1]]}], StyleBox["}", FontColor->GrayLevel[0]]}]}], StyleBox[";", FontColor->GrayLevel[0]]}], "\[IndentingNewLine]", RowBox[{ StyleBox[\({u, v} = {u, v}\/\@\(u\^2 + v\^2\);\), FontColor->GrayLevel[0]], StyleBox[" ", FontColor->GrayLevel[0]], StyleBox[\( (*Comment : \ This\ normalizes\ the\ vector*) \), FontColor->RGBColor[0, 0, 1]]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ StyleBox["m", FontColor->GrayLevel[0]], StyleBox["=", FontColor->GrayLevel[ 0]], \(\[PartialD]\_t\ f[x0 + t\ u, y0 + t\ v] /. t \[Rule] 0\)}], ";", StyleBox[ RowBox[{" ", StyleBox[" ", FontColor->GrayLevel[0]]}]], StyleBox[\( (*Comment : \ This\ calculates\ the\ directional\ derivative . \ \ \ Mathematica\ uses\ /. \ to\ substitute\ the\ thing\ on\ the\ right\ side\ of\ the\ \ following\ arrow\ for\ the\ variable\ on\ the\ left\ side\ of\ the\ arrow, \ after\ perfoming\ the\ calculation\ to\ the\ left\ of\ the\ /. \ \(\(.\)\(\ \)\(In\)\)\ this\ case\ it\ takes\ the\ derivative\ of\ the\ \ function\ with\ respect\ to\ t\ and\ then\ substitutes\ 0\ for\ t*) \), FontColor->RGBColor[0, 0, 1]], "\[IndentingNewLine]", \(Print["\", ToString[f[x, y], TraditionalForm], "\< at the point \>", ToString[{x0, y0}, TraditionalForm], "\< in the direction of \>", ToString[{u, v}, TraditionalForm], "\< is \>", ToString[m, TraditionalForm]]\)}], "\[IndentingNewLine]", RowBox[{ RowBox[{"intPlot", "=", RowBox[{"Show", "[", RowBox[{"surfPlot", ",", RowBox[{"Graphics3D", "[", RowBox[{"Polygon", "[", RowBox[{"{", RowBox[{\({x0 - 3\ u, y0 - 3 v, Min[surfPlot[\([1]\)]]}\), ",", \({x0 - 3\ u, y0 - 3\ v, Max[surfPlot[\([1]\)]]}\), ",", RowBox[{"{", RowBox[{\(x0 + 3\ u\), StyleBox[",", FontColor->GrayLevel[0]], RowBox[{ StyleBox["y0", FontColor->GrayLevel[0]], StyleBox["+", FontColor->GrayLevel[0]], RowBox[{"3", StyleBox[" ", FontColor->GrayLevel[0]], "v"}]}], ",", \(Max[surfPlot[\([1]\)]]\)}], "}"}], ",", RowBox[{"{", RowBox[{\(x0 + 3\ u\), StyleBox[",", FontColor->GrayLevel[0]], RowBox[{ StyleBox["y0", FontColor->GrayLevel[0]], StyleBox["+", FontColor->GrayLevel[0]], RowBox[{"3", StyleBox[" ", FontColor->GrayLevel[0]], "v"}]}], ",", \(Min[surfPlot[\([1]\)]]\)}], "}"}]}], "}"}], "]"}], "]"}], ",", \(DisplayFunction \[Rule] Identity\)}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"crossPlot", "=", RowBox[{"Plot", "[", RowBox[{\({f[x0 + t\ u, y0 + t\ v], m\ t + f[x0, y0]}\), ",", RowBox[{"{", RowBox[{"t", ",", StyleBox[\(-2\), FontColor->RGBColor[1, 0, 1]], ",", StyleBox["2", FontColor->RGBColor[1, 0, 1]]}], "}"}], ",", \(PlotStyle \[Rule] {RGBColor[0, 0, 1], RGBColor[1, 0, 0]}\), ",", \(DisplayFunction \[Rule] Identity\), ",", \(AxesLabel \[Rule] {"\", \ "\< \>"}\)}], "]"}]}], ";"}], "\[IndentingNewLine]", \(Show[ Graphics[Rectangle[{0, 0}, {1, 1}, intPlot]], Graphics[Rectangle[{1, 0}, {2, 1}, crossPlot]], DisplayFunction \[Rule] $DisplayFunction, ImageSize \[Rule] 72\ 7];\)}], "Input", FontSize->14], Cell[TextData[{ "You may have seen another way to find the directional derivative. You can \ find the gradient of the function at the chosen point and combine it with the \ direction vector using something called a \"dot product.\" The next three \ input cells do this. ", StyleBox["Make sure the input cell above is the last one you evaluated in \ this ", FontColor->RGBColor[1, 0, 1]], StyleBox["Mathematica", FontSlant->"Italic", FontColor->RGBColor[1, 0, 1]], StyleBox[" session, and then evaluate each of the next three input cells in \ the order they appear.", FontColor->RGBColor[1, 0, 1]] }], "Text", FontSize->14], Cell["\<\ The next cell computes the gradient of the function f[x,y] athe the point \ {x0,y0}, with the function and point from the previous input cell.\ \>", "Text", FontSize->14], Cell[BoxData[{ \(Clear[grad]\), "\[IndentingNewLine]", \(grad = {\[PartialD]\_x\ f[x, y], \[PartialD]\_y\ f[x, y]} /. {x \[Rule] \ x0, y \[Rule] y0}\)}], "Input"], Cell[TextData[{ "The direction vector needs to be a unit vector in order for this number to \ represent the instaneous rate of change of the function in that direction. \ We converted the original vector {u,v} into a unit vector in the first input \ cell, and it is that unit vector that has now been stored as {u,v}. The next \ cell shows both the unit vector and computes its length (using the ", StyleBox["Mathematica", FontSlant->"Italic"], " command ", StyleBox["Norm", FontColor->RGBColor[1, 0, 0]], ". That length should be 1." }], "Text", FontSize->14], Cell[BoxData[{ \({u, v}\), "\[IndentingNewLine]", \(Norm[{u, v}]\)}], "Input"], Cell[TextData[{ "The next cell computes the directional derivative using the dot product of \ the gradient and the direction. ", StyleBox["Evaluate it", FontColor->RGBColor[1, 0, 1]], " compare the answer to the one you got in the first input cell in this \ section, which used the derivative of the function f[x0+tu,y0+tv] at t = 0 to \ find the directional derivative." }], "Text", FontSize->14], Cell[BoxData[ \(grad . {u, v}\)], "Input"] }, Closed]], Cell[CellGroupData[{ Cell["A maximal directional derivative", "Section"], Cell[TextData[{ "You can use the above definition of the directional derivative to get ", StyleBox["Mathematica", FontSlant->"Italic"], " to hunt for a maximal rate of change of a function (i.e. a maximal \ directional derivative). What you do is to create a whole range of \ directions and have ", StyleBox["Mathematica", FontSlant->"Italic"], " calculate the directional derivative in each of those directions. You \ can then narrow down your search by choosing a smaller range containing the \ direction associated with the largest directional derivative computed." }], "Text", FontSize->14], Cell[TextData[{ "One way to create this range of directions is to choose a collection of \ angles in the x-y plane. You can specify a smallest and largest angle to \ check, and to have ", StyleBox["Mathematica", FontSlant->"Italic"], " automatically divide that interval of angles into equally spaced sizes. \ For instance, the second cell below divides the range of angles from 0 to ", Cell[BoxData[ \(TraditionalForm\`4\/3\)]], "\[Pi] (angles measured in RADIANS!) into 15 equal sized pieces and finds \ normalized direction vectors associated to each angle. The output will be a \ picture of the directions and a table consisting of the angles and the \ associated directions (changed to approximation form). To draw the picture, \ we need to have ", StyleBox["Mathematica", FontSlant->"Italic"], " load a special package, which is done in the next cell. It has been set \ as an \"initialization\" cell, so it should already have been evaluated. ", StyleBox["Look at its output and make sure the package \"Graphics`Arrow`\" \ is listed. If not, re-evaluate the cell.", FontColor->RGBColor[1, 0, 1]] }], "Text", FontSize->14], Cell[BoxData[{ \(Needs["\"]\), "\[IndentingNewLine]", \($Packages\)}], "Input", InitializationCell->True, FontSize->14], Cell[TextData[{ "Now ", StyleBox["evaluate the next cell", FontColor->RGBColor[1, 0, 1]], " to draw the picture and create the table." }], "Text", FontSize->14], Cell[BoxData[{\(Clear[\[Theta]min, \[Theta]max, n]\), "\n", RowBox[{ RowBox[{"\[Theta]min", "=", StyleBox["0", FontColor->RGBColor[1, 0, 1]]}], ";"}], "\n", RowBox[{ RowBox[{"\[Theta]max", "=", StyleBox[\(\(4\/3\) \[Pi]\), FontColor->RGBColor[1, 0, 1]]}], ";"}], "\n", RowBox[{ RowBox[{"n", "=", StyleBox["15", FontColor->RGBColor[1, 0, 1]]}], ";"}], "\n", \(Show[ Graphics[ Table[Arrow[{0, 0}, {Cos[\[Theta]min + \(\(\[Theta]max - \[Theta]min\)\/n\) k], Sin[\[Theta]min + \(\(\[Theta]max - \ \[Theta]min\)\/n\) k]}], {k, 0, n}]], AspectRatio \[Rule] Automatic];\), "\n", \(TableForm[ Table[{N[\[Theta]min + \(\(\[Theta]max - \[Theta]min\)\/n\) k], N[\((\[Theta]min + \(\(\[Theta]max - \[Theta]min\)\/n\) k)\)\ 180\/\[Pi]], u = N[Cos[\[Theta]min + \(\(\[Theta]max - \[Theta]min\)\/n\) k]], v = N[Sin[\[Theta]min + \(\(\[Theta]max - \[Theta]min\)\/n\) k]]}, {k, 0, n}], TableHeadings \[Rule] {{\ }, {"\", "\", "\", "\"}}]\)}], "Input", FontSize->14], Cell[TextData[{ "You should now ", StyleBox["go back and re-evaluate the last cell", FontColor->RGBColor[1, 0, 1]], " after changing the values of ", StyleBox["\[Theta]min", FontColor->RGBColor[1, 0, 1]], " and ", StyleBox["\[Theta]max", FontColor->RGBColor[1, 0, 1]], " in order to narrow down the range of angles. That is what you will also \ do in the next part, but in that cell we also add the direction (in ", StyleBox["red", FontColor->RGBColor[1, 0, 0]], ") of the gradient vector of the function at the designated point to the \ picture. (If the gradient vector at that point is the zero vector, it will \ show as a ", StyleBox["red", FontColor->RGBColor[1, 0, 0]], " point rather than a ", StyleBox["red", FontColor->RGBColor[1, 0, 0]], " arrow.)" }], "Text", FontSize->14], Cell[TextData[{ "In order to do the search, you will need to input a function ", StyleBox["f[x,y]", FontColor->RGBColor[1, 0, 0]], ", a point ", StyleBox["{x0,y0} ", FontColor->RGBColor[1, 0, 0]], "where you are trying to find the maximal rate of change, a range of angles \ (in RADIANS, not degrees) to search, and how many subdivisions ", StyleBox["n", FontColor->RGBColor[1, 0, 0]], " of that range to use. To refine your search and \"zero-in\" on the \ actual direction and rate of change, simply change the range of angles (and \ possibly the number of subdivisions). The output is a table with four \ columns. The first is the angle in radians, the second the angle in degrees, \ the next two columns give you the direction associated with the angle (notice \ that it is NORMALIZED), and the last column is the directional derivative in \ that direction. To get you started, the cell below uses the function f(x,y) \ = 3 ", Cell[BoxData[ FormBox[ SuperscriptBox[ StyleBox["x", FontWeight->"Plain", FontSlant->"Plain", FontTracking->"Plain", FontVariations->{"Underline"->False, "Outline"->False, "Shadow"->False, "StrikeThrough"->False, "Masked"->False, "CompatibilityType"->0, "RotationAngle"->0}], "2"], TraditionalForm]]], "y and the point (1,2), a range from ", StyleBox["0", FontColor->RGBColor[1, 0, 1]], " to ", StyleBox["2 \[Pi]", FontColor->RGBColor[1, 0, 1]], ", and ", StyleBox["20", FontColor->RGBColor[1, 0, 1]], " subdivisions. ", StyleBox["Evaluate it.", FontColor->RGBColor[1, 0, 1]] }], "Text", FontSize->14], Cell[BoxData[{\(Clear[f, x, y, x0, y0, \[Theta]min, \[Theta]max, n, grad, u, v, k]\), "\[IndentingNewLine]", RowBox[{\(f[x_, y_]\), ":=", StyleBox[\(3\ x\^2\ y\), FontColor->RGBColor[1, 0, 1]]}], "\[IndentingNewLine]", RowBox[{ RowBox[{\({x0, y0}\), "=", RowBox[{"{", RowBox[{ StyleBox["1", FontColor->RGBColor[1, 0, 1]], ",", StyleBox["2", FontColor->RGBColor[1, 0, 1]]}], "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"\[Theta]min", "=", StyleBox["0", FontColor->RGBColor[1, 0, 1]]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"\[Theta]max", "=", StyleBox[\(2 \[Pi]\), FontColor->RGBColor[1, 0, 1]]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"n", "=", StyleBox["20", FontColor->RGBColor[1, 0, 1]]}], ";"}], "\[IndentingNewLine]", \(grad = {\[PartialD]\_x\ f[x, y], \[PartialD]\_y\ f[x, y]} /. {x \[Rule] x0, y \[Rule] y0};\), "\[IndentingNewLine]", \(Show[ Graphics[{Table[ Arrow[{0, 0}, {Cos[\[Theta]min + \(\(\[Theta]max - \[Theta]min\)\/n\) k], Sin[\[Theta]min + \(\(\[Theta]max - \[Theta]min\)\ \/n\) k]}], {k, 0, n}], \[IndentingNewLine]Hue[0], If[grad \[Equal] {0, 0}, {PointSize[ .03], RGBColor[1, 0, 0], Point[{0, 0}]}, Arrow[{0, 0}, grad\/Norm[grad]]]}], AspectRatio \[Rule] Automatic];\), "\[IndentingNewLine]", \(TableForm[ Table[{N[\[Theta]min + \(\(\[Theta]max - \[Theta]min\)\/n\) k], N[\((\[Theta]min + \(\(\[Theta]max - \[Theta]min\)\/n\) k)\)\ 180\/\[Pi]], u = N[Cos[\[Theta]min + \(\(\[Theta]max - \[Theta]min\)\/n\) k]], v = N[Sin[\[Theta]min + \(\(\[Theta]max - \[Theta]min\)\/n\) k]], \[PartialD]\_t\ f[x0 + t\ u, y0 + t\ v] /. t \[Rule] 0}, {k, 0, n}], TableHeadings \[Rule] {{\ }, {"\", "\", \ "\", "\", "\"}}]\)}], "Input", FontSize->14], Cell["\<\ Exercise 1: Narrow the range of angles by choosing two that flank the angle \ in the output table that has the largest directional derivative. Repeat this \ process a second time. Then estimate the direction in which the function \ seems to grow the most rapidly. What is the rate of growth in this \ direction?\ \>", "Text", CellFrame->True, FontSize->14, Background->GrayLevel[0.833326]], Cell["Ans:", "Text", CellFrame->True, FontSize->14], Cell[TextData[{ "When you are done, compare your result to the angle (with respect to the \ x-axis), direction and magnitude of the gradient vector by ", StyleBox["evaluating the next cell", FontColor->RGBColor[1, 0, 1]], ". (Note: If, by some chance, the gradient is the zero vector, then it \ will not have an angle or direction, and those lines will be left blank.)" }], "Text", FontSize->14], Cell[BoxData[{ \(Clear[grad]\), "\[IndentingNewLine]", \(TableForm[ N[{grad = {\[PartialD]\_x\ f[x, y], \[PartialD]\_y\ f[x, y]} /. {x \[Rule] x0, y \[Rule] y0}, If[grad[\([1]\)] < 0, \[Pi] + ArcTan[grad[\([2]\)]\/grad[\([1]\)]], If[grad[\([1]\)] > 0, If[grad[\([2]\)] >= 0, ArcTan[grad[\([2]\)]\/grad[\([1]\)]], 2\ \[Pi] + ArcTan[grad[\([2]\)]\/grad[\([1]\)]]], If[grad[\([2]\)] \[Equal] 0, "\< \>", If[grad[\([2]\)] > 0, \[Pi]\/2, \(3\ \[Pi]\)\/2]]]], If[grad[\([1]\)] < 0, 180 + ArcTan[grad[\([2]\)]\/grad[\([1]\)]]\ 180\/\[Pi], If[grad[\([1]\)] > 0, If[grad[\([2]\)] >= 0, ArcTan[grad[\([2]\)]\/grad[\([1]\)]]\ 180\/\[Pi], 360 + ArcTan[grad[\([2]\)]\/grad[\([1]\)]]\ 180\/\[Pi]], If[grad[\([2]\)] \[Equal] 0, "\< \>", If[grad[\([2]\)] > 0, 90, 270]]]], If[grad \[Equal] {0, 0}, "\< \>", grad\/Norm[grad]], Norm[grad]}], TableHeadings \[Rule] {{"\", "\", "\", "\", "\"}, {\ }}]\)}], "Input", FontSize->14], Cell["\<\ Exercise 2: Copy the syntax for the input cell just above Exercise 1 and \ paste it between this cell and the next answer cell. Change the point in the \ syntax from {1,2} to one of your own choice, and then repeat Exercise 1 with \ the new point. \ \>", "Text", CellFrame->True, FontSize->14, Background->GrayLevel[0.833326]], Cell["Ans:", "Text", CellFrame->True, FontSize->14], Cell[TextData[{ "When you are done, once again compare your result to the angle (with \ respect to the x-axis), direction and magnitude of the gradient vector by ", StyleBox["evaluating the next cell", FontColor->RGBColor[1, 0, 1]], "." }], "Text", FontSize->14], Cell[BoxData[{ \(Clear[grad]\), "\[IndentingNewLine]", \(TableForm[ N[{grad = {\[PartialD]\_x\ f[x, y], \[PartialD]\_y\ f[x, y]} /. {x \[Rule] x0, y \[Rule] y0}, If[grad[\([1]\)] < 0, \[Pi] + ArcTan[grad[\([2]\)]\/grad[\([1]\)]], If[grad[\([1]\)] > 0, If[grad[\([2]\)] >= 0, ArcTan[grad[\([2]\)]\/grad[\([1]\)]], 2\ \[Pi] + ArcTan[grad[\([2]\)]\/grad[\([1]\)]]], If[grad[\([2]\)] \[Equal] 0, "\< \>", If[grad[\([2]\)] > 0, \[Pi]\/2, \(3\ \[Pi]\)\/2]]]], If[grad[\([1]\)] < 0, 180 + ArcTan[grad[\([2]\)]\/grad[\([1]\)]]\ 180\/\[Pi], If[grad[\([1]\)] > 0, If[grad[\([2]\)] >= 0, ArcTan[grad[\([2]\)]\/grad[\([1]\)]]\ 180\/\[Pi], 360 + ArcTan[grad[\([2]\)]\/grad[\([1]\)]]\ 180\/\[Pi]], If[grad[\([2]\)] \[Equal] 0, "\< \>", If[grad[\([2]\)] > 0, 90, 270]]]], If[grad \[Equal] {0, 0}, "\< \>", grad\/Norm[grad]], Norm[grad]}], TableHeadings \[Rule] {{"\", "\", "\", "\", "\"}, {\ }}]\)}], "Input", FontSize->14], Cell["\<\ Exercise 3: This time repeat Exercise 2, but choose a different function \ instead of a different point.\ \>", "Text", CellFrame->True, FontSize->14, Background->GrayLevel[0.833326]], Cell["Ans:", "Text", CellFrame->True, FontSize->14], Cell[TextData[{ "When you are done, once again compare your result to the angle (with \ respect to the x-axis), direction and magnitude of the gradient vector ", StyleBox["evaluating the next cell", FontColor->RGBColor[1, 0, 1]], "." }], "Text", FontSize->14], Cell[BoxData[{ \(Clear[grad]\), "\[IndentingNewLine]", \(TableForm[ N[{grad = {\[PartialD]\_x\ f[x, y], \[PartialD]\_y\ f[x, y]} /. {x \[Rule] x0, y \[Rule] y0}, If[grad[\([1]\)] < 0, \[Pi] + ArcTan[grad[\([2]\)]\/grad[\([1]\)]], If[grad[\([1]\)] > 0, If[grad[\([2]\)] >= 0, ArcTan[grad[\([2]\)]\/grad[\([1]\)]], 2\ \[Pi] + ArcTan[grad[\([2]\)]\/grad[\([1]\)]]], If[grad[\([2]\)] \[Equal] 0, "\< \>", If[grad[\([2]\)] > 0, \[Pi]\/2, \(3\ \[Pi]\)\/2]]]], If[grad[\([1]\)] < 0, 180 + ArcTan[grad[\([2]\)]\/grad[\([1]\)]]\ 180\/\[Pi], If[grad[\([1]\)] > 0, If[grad[\([2]\)] >= 0, ArcTan[grad[\([2]\)]\/grad[\([1]\)]]\ 180\/\[Pi], 360 + ArcTan[grad[\([2]\)]\/grad[\([1]\)]]\ 180\/\[Pi]], If[grad[\([2]\)] \[Equal] 0, "\< \>", If[grad[\([2]\)] > 0, 90, 270]]]], If[grad \[Equal] {0, 0}, "\< \>", grad\/Norm[grad]], Norm[grad]}], TableHeadings \[Rule] {{"\", "\", "\", "\", "\"}, {\ }}]\)}], "Input", FontSize->14] }, Closed]] }, Open ]] }, FrontEndVersion->"5.2 for Microsoft Windows", ScreenRectangle->{{0, 1280}, {0, 971}}, AutoGeneratedPackage->None, WindowToolbars->"EditBar", WindowSize->{705, 635}, 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[1776, 53, 117, 3, 111, "Title"], Cell[1896, 58, 250, 4, 44, "SmallText"], Cell[2149, 64, 316, 9, 52, "Text"], Cell[CellGroupData[{ Cell[2490, 77, 116, 3, 99, "Section"], Cell[CellGroupData[{ Cell[2631, 84, 68, 0, 38, "Subsection"], Cell[2702, 86, 141, 3, 50, "Input", InitializationCell->True] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[2892, 95, 61, 0, 43, "Section"], Cell[2956, 97, 3279, 80, 419, "Text"], Cell[6238, 179, 6949, 173, 792, "Input"], Cell[13190, 354, 651, 15, 114, "Text"], Cell[13844, 371, 182, 4, 54, "Text"], Cell[14029, 377, 184, 3, 50, "Input"], Cell[14216, 382, 583, 13, 114, "Text"], Cell[14802, 397, 87, 2, 50, "Input"], Cell[14892, 401, 410, 9, 74, "Text"], Cell[15305, 412, 46, 1, 30, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[15388, 418, 51, 0, 43, "Section"], Cell[15442, 420, 616, 13, 114, "Text"], Cell[16061, 435, 1170, 23, 197, "Text"], Cell[17234, 460, 150, 4, 50, "Input", InitializationCell->True], Cell[17387, 466, 172, 6, 34, "Text"], Cell[17562, 474, 1239, 28, 369, "Input"], Cell[18804, 504, 837, 24, 114, "Text"], Cell[19644, 530, 1742, 46, 174, "Text"], Cell[21389, 578, 2185, 46, 563, "Input"], Cell[23577, 626, 409, 9, 90, "Text"], Cell[23989, 637, 55, 2, 50, "Text"], Cell[24047, 641, 408, 8, 74, "Text"], Cell[24458, 651, 1233, 22, 504, "Input"], Cell[25694, 675, 344, 8, 90, "Text"], Cell[26041, 685, 55, 2, 50, "Text"], Cell[26099, 689, 274, 7, 54, "Text"], Cell[26376, 698, 1233, 22, 504, "Input"], Cell[27612, 722, 199, 6, 50, "Text"], Cell[27814, 730, 55, 2, 50, "Text"], Cell[27872, 734, 271, 7, 54, "Text"], Cell[28146, 743, 1233, 22, 504, "Input"] }, Closed]] }, Open ]] } ] *) (******************************************************************* End of Mathematica Notebook file. *******************************************************************)