(*********************************************************************** 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[ 8728, 359]*) (*NotebookOutlinePosition[ 9395, 383]*) (* CellTagsIndexPosition[ 9351, 379]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell["Vector Manipulations with Mathematica", "Title", TextAlignment->Center, TextJustification->0, FontSize->18], Cell[CellGroupData[{ Cell["Clear symbols", "Section", Evaluatable->False, AspectRatioFixed->True], Cell["\<\ In order to avoid interference from symbols defined in other \ notebooks, we first Clear all symbols. We assume that the relevant symbols \ are in the Global` context.\ \>", "Text", Evaluatable->False, AspectRatioFixed->True], Cell["Clear[\"Global`*\"]", "Input", AspectRatioFixed->True] }, Open ]], Cell[CellGroupData[{ Cell["Overview", "Section", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[{ "Here are some applications of ", StyleBox["Mathematica", FontSlant->"Italic"], " to vectors, some taken from problems in Kleppner and Kolenkow's book on \ mechanics and some from Tam, \"A Physicist's Guide to ", StyleBox["Mathematica", FontSlant->"Italic"], "\".\n\nThe main thing is to load the Calculus`VectorAnalysis` package:" }], "Text"], Cell[BoxData[ \(<< Calculus`VectorAnalysis`\)], "Input"], Cell["Check what's in the package (note the \"\"'s):", "Text", Evaluatable->False, AspectRatioFixed->True], Cell[BoxData[ \(\(\(?\)\("\"\)\(\[IndentingNewLine]\)\)\)], \ "Input"], Cell["\<\ So there are the usual vector operations such as DotProduct, and \ Div, Grad, Curl, but also lots of different coordinate systems. When in \ doubt, look up a function in the Help Browser or use ? or ??:\ \>", "Text", Evaluatable->False, AspectRatioFixed->True], Cell[BoxData[ \(\(?Curl\)\)], "Input"], Cell[BoxData[ \(\(?ScalarTripleProduct\)\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Example 1 (K&K 1.1)", "Section", FontSize->14], Cell["\<\ Load the vector package (if not already loaded, that's what Needs \ does!), define some vectors, and carry out the desired operations.\ \>", \ "Text"], Cell[BoxData[ \(Needs["\"]\)], "Input"], Cell[BoxData[ \(A\ = \ {2, \(-3\), 7}\)], "Input"], Cell[BoxData[ \(B\ = \ {5, 1, 2}\)], "Input"], Cell[BoxData[ \(A + B\)], "Input"], Cell[BoxData[ \(A - B\)], "Input"], Cell[BoxData[ \(DotProduct[A, B]\)], "Input"], Cell[BoxData[ \(CrossProduct[A, B]\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Example 2 (K&K 1.2)", "Section", FontSize->14], Cell[TextData[{ "Here we'll define a function Mag to calculate the magnitude of a vector \ (since one is not defined in ", StyleBox["Mathematica", FontSlant->"Italic"], ").\nDefine it in terms of the dot product of the vector with itself:" }], "Text"], Cell[BoxData[ \(Needs["\"]\)], "Input"], Cell[BoxData[ \(Mag[v_]\ := \ Sqrt[DotProduct[v, v]]\)], "Input"], Cell["Try it out:", "Text"], Cell[BoxData[ \(Clear[A, B]\)], "Input"], Cell[BoxData[ \(A\ = \ {3, 1, 1}\)], "Input"], Cell[BoxData[ \(B\ = \ {\(-2\), \(-3\), \(-1\)}\)], "Input"], Cell[BoxData[ \(ans\ = \ DotProduct[A, B]/\((Mag[A]\ Mag[B])\)\)], "Input"], Cell["\<\ This should be the cosine of the angle between the vectors. \ Numerical value:\ \>", "Text"], Cell[BoxData[ \(N[ans]\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Example 3 (K&K 2.1)", "Section", FontSize->14], Cell["\<\ Here we integrate some vector functions of time, starting from a \ force given in Cartesian coordinates.\ \>", "Text"], Cell[BoxData[ \(Needs["\"]\)], "Input"], Cell["\<\ First we define functions with a dummy argument (signified by the \ underscore with t__). We use = rather than := because we don't need a delayed evaluation.\ \>", "Text"], Cell[BoxData[ \(F[t_]\ = \ {4\ t^2, \ \(-3\)\ t, \ 0}\)], "Input"], Cell[BoxData[ \(a[t_]\ = \ F[t]/m\)], "Input"], Cell["Note the use of a dummy integration variable tp (t'):", "Text"], Cell[BoxData[ \(v[t_]\ = \ Integrate[a[tp], {tp, 0, t}]\)], "Input"], Cell[BoxData[ \(r[t_]\ = \ Integrate[v[tp], {tp, 0, t}]\)], "Input"], Cell[BoxData[ \(CrossProduct[r[t], v[t]]\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Example 4", "Section", FontSize->14], Cell["Here we work with variable components instead of numbers: ", "Text"], Cell[BoxData[ \(Needs["\"]\)], "Input"], Cell[BoxData[ \(A\ = \ {Ax, Ay, Az}\)], "Input"], Cell[BoxData[ \(B\ = \ {Bx, By, Bz}\)], "Input"], Cell[BoxData[ \(DotProduct[A, B]\)], "Input"], Cell[TextData[{ "Show that ", StyleBox["A \[SmallCircle] (A \[Times] B)", FontWeight->"Bold"], " = 0 :" }], "Text"], Cell[BoxData[ \(V\ = \ DotProduct[A, CrossProduct[A, B]]\)], "Input"], Cell[TextData[{ "We have to tell ", StyleBox["Mathematica", FontSlant->"Italic"], " to simplify this expression:" }], "Text"], Cell[BoxData[ \(Simplify[V]\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Example 5 (K&K 5.1)", "Section", FontSize->14], Cell["This is a problem to calculate some gradients.", "Text"], Cell[BoxData[ \(Needs["\"]\)], "Input"], Cell["The first two are in Cartesian coordinates:", "Text"], Cell[BoxData[ \(SetCoordinates[Cartesian[x, y, z]]\)], "Input"], Cell["Part a. (note the - sign!):", "Text"], Cell[BoxData[ \(\(-Grad[\ A\ x^2\ + \ B\ y^2\ + \ C\ z^2]\)\)], "Input"], Cell["Part b.:", "Text"], Cell[BoxData[ \(\(-Grad[\ A\ Log[x^2\ + \ y^2\ + \ z^2]]\)\)], "Input"], Cell["For part c., we switch to Cylindrical coordinates:", "Text"], Cell[BoxData[ \(SetCoordinates[Cylindrical[r, theta, z]]\)], "Input"], Cell[BoxData[ \(\(-Grad[A\ Cos[theta]/r^2]\)\)], "Input"] }, Closed]], Cell[CellGroupData[{ Cell["Example 6 (K&K 5.2)", "Section", FontSize->14], Cell["\<\ To check this one, we'll use the Curl function in Cartesian and \ Cylindrical coordinates.\ \>", "Text"], Cell[BoxData[ \(Needs["\"]\)], "Input"], Cell[BoxData[ \(SetCoordinates[Cylindrical[r, theta, z]]\)], "Input"], Cell["Here we define a vector in Cylindrical coordinates in {}'s:", "Text"], Cell[BoxData[ \(Curl[{\(-A\)\ r^3, \ 0, \ 0}]\)], "Input"], Cell[BoxData[ \(SetCoordinates[Cartesian[x, y, z]]\)], "Input"], Cell[BoxData[ \(Curl[B*{y^2, \(-x^2\), 0}]\)], "Input"] }, Closed]], Cell[CellGroupData[{ Cell["Example 7 (K&K 5.8)", "Section", FontSize->14], Cell["\<\ Here we'll just check the Curl of a force F, dot it with the unit \ vector khat, and integrate over a two-dimensional square:\ \>", "Text"], Cell[BoxData[ \(Needs["\"]\)], "Input"], Cell[BoxData[ \(SetCoordinates[Cartesian[x, y, z]]\)], "Input"], Cell[BoxData[ \(curlF\ = \ Curl[A*{y^2, 2\ x^2, \ 0}]\)], "Input"], Cell[BoxData[ \(khat\ = \ {0, 0, 1}\)], "Input"], Cell[BoxData[ \(Integrate[Dot[curlF, khat], {x, 0, d}, {y, 0, d}]\)], "Input"] }, Closed]] }, Open ]] }, FrontEndVersion->"4.0 for X", ScreenRectangle->{{0, 1280}, {0, 1024}}, WindowToolbars->"EditBar", WindowSize->{690, 885}, WindowMargins->{{0, Automatic}, {Automatic, -11}} ] (*********************************************************************** 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, 119, 3, 93, "Title"], Cell[CellGroupData[{ Cell[1883, 58, 80, 2, 60, "Section", Evaluatable->False], Cell[1966, 62, 240, 6, 50, "Text", Evaluatable->False], Cell[2209, 70, 62, 1, 27, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[2308, 76, 75, 2, 60, "Section", Evaluatable->False], Cell[2386, 80, 377, 9, 86, "Text"], Cell[2766, 91, 60, 1, 27, "Input"], Cell[2829, 94, 110, 2, 32, "Text", Evaluatable->False], Cell[2942, 98, 102, 2, 43, "Input"], Cell[3047, 102, 275, 6, 50, "Text", Evaluatable->False], Cell[3325, 110, 42, 1, 27, "Input"], Cell[3370, 113, 57, 1, 27, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[3464, 119, 54, 1, 56, "Section"], Cell[3521, 122, 160, 4, 50, "Text"], Cell[3684, 128, 70, 1, 27, "Input"], Cell[3757, 131, 55, 1, 27, "Input"], Cell[3815, 134, 50, 1, 27, "Input"], Cell[3868, 137, 38, 1, 27, "Input"], Cell[3909, 140, 38, 1, 27, "Input"], Cell[3950, 143, 49, 1, 27, "Input"], Cell[4002, 146, 51, 1, 27, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[4090, 152, 54, 1, 56, "Section"], Cell[4147, 155, 261, 6, 50, "Text"], Cell[4411, 163, 70, 1, 27, "Input"], Cell[4484, 166, 70, 1, 27, "Input"], Cell[4557, 169, 27, 0, 32, "Text"], Cell[4587, 171, 44, 1, 27, "Input"], Cell[4634, 174, 50, 1, 27, "Input"], Cell[4687, 177, 65, 1, 27, "Input"], Cell[4755, 180, 80, 1, 27, "Input"], Cell[4838, 183, 104, 3, 32, "Text"], Cell[4945, 188, 39, 1, 27, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[5021, 194, 54, 1, 56, "Section"], Cell[5078, 197, 128, 3, 32, "Text"], Cell[5209, 202, 70, 1, 27, "Input"], Cell[5282, 205, 184, 5, 50, "Text"], Cell[5469, 212, 71, 1, 27, "Input"], Cell[5543, 215, 51, 1, 27, "Input"], Cell[5597, 218, 69, 0, 32, "Text"], Cell[5669, 220, 73, 1, 27, "Input"], Cell[5745, 223, 73, 1, 27, "Input"], Cell[5821, 226, 57, 1, 27, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[5915, 232, 44, 1, 56, "Section"], Cell[5962, 235, 74, 0, 32, "Text"], Cell[6039, 237, 70, 1, 27, "Input"], Cell[6112, 240, 53, 1, 27, "Input"], Cell[6168, 243, 53, 1, 27, "Input"], Cell[6224, 246, 49, 1, 27, "Input"], Cell[6276, 249, 125, 5, 32, "Text"], Cell[6404, 256, 74, 1, 27, "Input"], Cell[6481, 259, 135, 5, 32, "Text"], Cell[6619, 266, 44, 1, 27, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[6700, 272, 54, 1, 56, "Section"], Cell[6757, 275, 62, 0, 32, "Text"], Cell[6822, 277, 70, 1, 27, "Input"], Cell[6895, 280, 59, 0, 32, "Text"], Cell[6957, 282, 67, 1, 27, "Input"], Cell[7027, 285, 43, 0, 32, "Text"], Cell[7073, 287, 78, 1, 27, "Input"], Cell[7154, 290, 24, 0, 32, "Text"], Cell[7181, 292, 77, 1, 27, "Input"], Cell[7261, 295, 66, 0, 32, "Text"], Cell[7330, 297, 73, 1, 27, "Input"], Cell[7406, 300, 61, 1, 27, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[7504, 306, 54, 1, 36, "Section"], Cell[7561, 309, 114, 3, 32, "Text"], Cell[7678, 314, 70, 1, 27, "Input"], Cell[7751, 317, 73, 1, 27, "Input"], Cell[7827, 320, 75, 0, 32, "Text"], Cell[7905, 322, 62, 1, 27, "Input"], Cell[7970, 325, 67, 1, 27, "Input"], Cell[8040, 328, 59, 1, 27, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[8136, 334, 54, 1, 36, "Section"], Cell[8193, 337, 149, 3, 32, "Text"], Cell[8345, 342, 70, 1, 27, "Input"], Cell[8418, 345, 67, 1, 27, "Input"], Cell[8488, 348, 71, 1, 27, "Input"], Cell[8562, 351, 53, 1, 27, "Input"], Cell[8618, 354, 82, 1, 27, "Input"] }, Closed]] }, Open ]] } ] *) (*********************************************************************** End of Mathematica Notebook file. ***********************************************************************)