(*********************************************************************** 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[ 17225, 577]*) (*NotebookOutlinePosition[ 17887, 601]*) (* CellTagsIndexPosition[ 17843, 597]*) (*WindowFrame->Normal*) Notebook[{ Cell[TextData[StyleBox["Worksheet 0: The basics", FontSize->13]], "Text", FontWeight->"Bold"], Cell["\<\ [Name] [Date] [Section]\ \>", "Text"], Cell[TextData[{ "\nWelcome to ", StyleBox["PHY 102: ", FontWeight->"Bold"], StyleBox["Mathematica. ", FontWeight->"Bold", FontSlant->"Italic"], StyleBox[" ", FontSlant->"Italic"], "The goal of this class is to teach you ", StyleBox["Mathematica ", FontSlant->"Italic"], "so you can use it later on in your physics career (*it comes in handy). \ You will be assigned weekly worksheets to be handed in by each Friday. The \ assignments are required work, but additional ", StyleBox["Mathematica", FontSlant->"Italic"], StyleBox[" ", FontWeight->"Bold", FontSlant->"Italic"], "work is encouraged. ", StyleBox["\n\n", FontWeight->"Bold", FontSlant->"Italic"], "We'll begin with a description of some ", StyleBox["Mathematica", FontSlant->"Italic"], " fundamentals and illustrate them with examples. Don't worry too much \ about the details of these examples - they are just to give you an idea of \ the syntax of the language. We'll get into the details later on.\n\nYou are \ encouraged to evaluate and experiment with the examples in this worksheet. \ The goal of this is to give you a basic idea of ", StyleBox["Mathematica", FontSlant->"Italic"], ",", StyleBox[" ", FontWeight->"Bold"], "so feel free to explore.", StyleBox["\n", FontWeight->"Bold"], " " }], "Text"], Cell[CellGroupData[{ Cell[TextData[{ StyleBox["Cell Brackets", FontSize->14, FontWeight->"Bold"], StyleBox["\nMathematica", FontSlant->"Italic"], " ", StyleBox[" ", FontWeight->"Bold", FontSlant->"Italic"], "is unlike many other programming languages in that the commands may be \ separately run, as opposed to running the entire program all at once. ", StyleBox["Mathematica", FontSlant->"Italic"], " accomplishes this by using brakets to group commands. Note the blue \ bracket to the right of this text. These blue brackets designate cell \ groups. When a command is executed, all commands within the given cell group \ are processed. This allows you to examine the results of one set of \ computations before proceeding onto the next set.\.18" }], "Text"], Cell[TextData[{ "Example: ", StyleBox[" Evaluate the commands in the next bracket. Do this by moving \ the cursor down to the next bracket and pressing [shift]+[enter] to evaluate \ its commands.", FontWeight->"Plain"] }], "Text", FontWeight->"Bold"], Cell[BoxData[{ \(8/\((2 + 3)\)\), "\[IndentingNewLine]", \({x0, y0}\ = {5, \ 10}\), "\[IndentingNewLine]", \(MatrixForm[{{2, 3, 4}, {6, 3, 6}, {2, 4, 1}}]\)}], "Input"], Cell["\<\ Note that the second command prints to the screen, even though we \ are just assigning values to x0 and y0. Generally, assignments such as these \ are not intended to produce output. This output can be \"silenced\" by \ adding a semicolon at the end of the line. Try evaluating: \ \>", "Text"], Cell[BoxData[ \(\({x0, y0} = {5, 10};\)\)], "Input"], Cell[TextData[{ StyleBox["Creating Cells. ", FontWeight->"Bold"], "To start a new cell group, move the cursor to a position 'between' two \ existing cell groups. The cursor turns into a horizontal line. Create the \ group by simply typing something 'into' the horizontal line. A new cell \ bracket will be created. However, note that *this* text is in a separate \ bracket than the mathematica commands in the examples. When beginning a \ group (i.e. when the cursor turns into a horizontal line), you can specify \ the group type (text, normal, etc..) by going to Format...Style and chosing \ the appropriate option. By default, newly created cells are interpreted as \ being commands. However, you do not want to put regular text in command \ form:" }], "Text"], Cell[BoxData[ \(This\ is\ a\ command\ group . It' s\ a\ bad\ idea\ to\ type\ text\ in\ \(here!\)\ \ Use\ the\ text\ \ setting\ for\ \ program\ \(comments!\)\)], "Input"] }, Open ]], Cell["", "Text"], Cell[CellGroupData[{ Cell[TextData[{ StyleBox["Using [ ], ( ), and { }\n", FontSize->14], StyleBox["One of the major difficulties in first learning ", FontSize->12, FontWeight->"Plain"], StyleBox["Mathematica", FontSize->12, FontWeight->"Plain", FontSlant->"Italic"], StyleBox[" is distinguishing between brackets, braces, and parenthesis. \n\ \nSquare brackets [ ] are used to indicate the arguments of a function. For \ instance, ", FontSize->12, FontWeight->"Plain"] }], "Text", FontSize->13, FontWeight->"Bold"], Cell[BoxData[{ \(Cos[\[Pi]/4]\), "\[IndentingNewLine]", \(Factor[x^2\ + \ 4 x\ - \ 12]\)}], "Input"], Cell["\<\ Parentheses ( ) are used to group expressions or to override order of \ operation:\ \>", "Text"], Cell[BoxData[{ \(2*5 + 8\), "\[IndentingNewLine]", \(2*\((5 + 8)\)\)}], "Input"], Cell["\<\ Braces { } are used for \"general grouping purposes.\" Note the \ different uses of { } in the following commands: \ \>", "Text"], Cell[BoxData[{ \(Plot[{Cos[x], Sin[x]}, {x, 0, 2 \[Pi]}]\), "\[IndentingNewLine]", \(\(x\ = \ {3, 5, 7};\)\), "\[IndentingNewLine]", \(\(y = {a, b, c};\)\), "\[IndentingNewLine]", \(x - y\)}], "Input"] }, Open ]], Cell["", "Text"], Cell[CellGroupData[{ Cell[TextData[{ "Capitalization\n", StyleBox["Mathematica", FontSize->12, FontWeight->"Plain", FontSlant->"Italic"], StyleBox[" is case sensitive. ", FontSize->12, FontWeight->"Plain"], StyleBox["Every built-in function is capitalized", FontSize->12], StyleBox[". Usually ", FontSize->12, FontWeight->"Plain"], StyleBox["Mathematica", FontSize->12, FontWeight->"Plain", FontSlant->"Italic"], StyleBox[" gives you informative error messages, saying \"I think you meant \ Cos[x] and not cos[x],\" but other times, you're not so lucky. \ Capitalization is usually a good place to start looking if your program \ doesn't work and you have no idea why. Try evaluating:", FontSize->12, FontWeight->"Plain"] }], "Text", FontSize->14, FontWeight->"Bold"], Cell[BoxData[{ \(Cos[\[Pi]]\), "\[IndentingNewLine]", \(cos[\[Pi]]\)}], "Input"], Cell["\<\ Also, if at one point you define X=10, don't be confused later on \ when 5*x does not equal 50. Be careful!\ \>", "Text"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "\n", StyleBox["Function Definition", FontSize->14, FontWeight->"Bold"], "\nDefining functions is also a bit tricky. First, when you define a \ function, the parameters of the function must end in a _ in the brackets. \ Second, there must be a : before the equals sign.\n\n", StyleBox["Examples:", FontWeight->"Bold"] }], "Text"], Cell[BoxData[{ \(\(f[x_] := 15 x\^2\ - \ 10 x\ + \ 3;\)\), "\[IndentingNewLine]", \(\(g[x_, y_] := \@\(x^2\ + \ y^2\);\)\[IndentingNewLine]\), "\ \[IndentingNewLine]", \(f[10]\), "\[IndentingNewLine]", \(g[2, 4]\)}], "Input"] }, Open ]], Cell["\<\ \ \>", "Text"], Cell[CellGroupData[{ Cell[TextData[{ "Equality\n", StyleBox["There are two kinds of equality. (Some variables are MORE equal \ than others...) First, there is the assignment equality: ", FontSize->12, FontWeight->"Plain"] }], "Text", FontSize->14, FontWeight->"Bold"], Cell[BoxData[ \(\(x = \ 10;\)\)], "Input"], Cell["And then you can also test for equality: (does x = 10?):", "Text"], Cell[BoxData[ \(x\ \[Equal] \ 10\)], "Input"], Cell[" The == operator is also used in any Solve[] functions:", "Text"], Cell[BoxData[ \(Solve[2 z \[Equal] 48, \ z]\)], "Input"], Cell[TextData[{ "Make sure you get these right! It's another stumbling block for ", StyleBox["Mathematica", FontSlant->"Italic"], " beginners. One single = sign is very hard to pick out in a complex \ program that just ", StyleBox["won't work", FontSlant->"Italic"], ", so make sure you get it right the first time.", " " }], "Text"] }, Open ]], Cell["\<\ \ \>", "Text"], Cell[TextData[{ StyleBox["Substitution\n", FontWeight->"Bold"], StyleBox["Another handy feature in ", FontSize->12], StyleBox["Mathematica", FontSize->12, FontSlant->"Italic"], StyleBox[" is the ability to substitute into expressions. A substition is \ written like this:", FontSize->12] }], "Text", FontSize->14], Cell[BoxData[ \(\(\(\[IndentingNewLine]\)\(p\^2 /. \ p \[Rule] 10\)\)\)], "Input"], Cell["Another example of the substitution rule:", "Text"], Cell[BoxData[{ \(\(sol\ = \ Solve[p^2\ - \ 3 p\ \[Equal] \ 0, \ p];\)\), "\[IndentingNewLine]", \(p\ /. sol\)}], "Input"], Cell[TextData[{ "\n", StyleBox["Plotting\n", FontSize->14, FontWeight->"Bold"], "The basic syntax for plotting is:\nPlot[f[x],{x,xmin,xmax}]\n\nOther \ plotting commands include ListPlot and ParametricPlot, which have very \ similar syntax to Plot.\n" }], "Text"], Cell[BoxData[{ \(f[x_] := Log[x]\), "\[IndentingNewLine]", \(Plot[Sin[x], {x, 0, 2 \[Pi]}]\), "\[IndentingNewLine]", \(Plot[Erf[x], {x, \(-10\), 10}]\), "\[IndentingNewLine]", \(Plot[f[x], {x, 1, 10}]\)}], "Input"], Cell[TextData[{ StyleBox["Evaluating.", FontWeight->"Bold"], " One common problem with plotting functions is that ", StyleBox["Mathematica", FontSlant->"Italic"], " has not yet evaluated a function when it goes to plot it. The way to fix \ this is by using:\n\nPlot[ Evaluate[[f[x]],{x,xmin,xmax}]\n" }], "Text"], Cell[TextData[{ "Clearing Variables\n", StyleBox["When you define variables in ", FontSize->12, FontWeight->"Plain"], StyleBox["Mathematica", FontSize->12, FontWeight->"Plain", FontSlant->"Italic"], StyleBox[", they stay resident in memory for future use. This can be a \ problem if you have two separate parts of a worksheet, each using 'x' in a \ different way. The memory can be cleared of all variables by using the \ command:", FontSize->12, FontWeight->"Plain"] }], "Text", FontSize->14, FontWeight->"Bold"], Cell[BoxData[ \(Remove["\"]\)], "Input"], Cell["\<\ It is usually a good idea to use Remove[ ] between different \ questions on your worksheet (as long as the second section does not use \ anything from the first).\ \>", "Text"], Cell[TextData[{ "\n\n", StyleBox["Using Help", FontSize->26, FontWeight->"Bold"], "\n", StyleBox["Mathematica", FontSlant->"Italic"], " has an incredible built-in help system that can very easily become your \ best friend. To see for yourself, goto Help...Built-in functions, and type \ Plot.\n\nWhat you will see is the quick-and-dirty refrence guide to using \ Plot, and all the neat things you can do with it. You can also see examples \ of several Plot statements and evaluate them for yourself.\n\nNote that at \ the bottom of the examples of Plot, you will see:" }], "Text"], Cell[BoxData[ \(Options[Plot]\)], "Input"], Cell["\<\ This is a list of all the different options that go along with \ Plot. (Options[] works for any function). So if you decide to make your \ plot pretty and add color, Options[] would probably be the best place to find \ out how. \ \>", "Text"], Cell[TextData[StyleBox["Some Commonly Used Functions", FontWeight->"Bold"]], "Subtitle", FontSize->16, FontWeight->"Plain"], Cell[TextData[{ StyleBox["N[]:", FontWeight->"Bold"], " Returns the numeric value of an expression." }], "Text", FontWeight->"Plain"], Cell[BoxData[{ \(5/8\), "\[IndentingNewLine]", \(N[5/8]\)}], "Input"], Cell[TextData[{ StyleBox["Plot[]:", FontWeight->"Bold"], " The basic plotter in ", StyleBox["Mathematica", FontSlant->"Italic"], ":" }], "Text"], Cell[BoxData[ \(Plot[Cos[x], {x, \(-2\) \[Pi], 2 \[Pi]}]\)], "Input"], Cell[TextData[{ StyleBox["ParametricPlot[]:", FontWeight->"Bold"], " Generates a parametric plot:" }], "Text"], Cell[BoxData[{ \(ParametricPlot[{Cos[t], Sin[2 t - \[Pi]]}, {t, 0, 5 \[Pi]}]\), "\[IndentingNewLine]", \(ParametricPlot[{10 t, 100 - t^2}, {t, 0, 10}]\)}], "Input"], Cell[TextData[{ StyleBox["ListPlot[]:", FontWeight->"Bold"], " Plots a list of values on the y axis, taking the x axis to be the \ sequence {1,2,3...}" }], "Text"], Cell[BoxData[ \(ListPlot[{4, 7, 2, 3, 5, 2, 3, 6}]\)], "Input"], Cell[TextData[{ StyleBox["DSolve[]:", FontWeight->"Bold"], " The differential equation solver. This attempts to find solutions of \ differential equations analytically. In order for this to work, you need to \ specify the appropriate initial conditions." }], "Text"], Cell[BoxData[{ \(Remove["\"]\), "\[IndentingNewLine]", \(\({x0, \ dx0} = {1, 2};\)\), "\[IndentingNewLine]", \(DSolve[{\(x''\)[t] + 4 x[t] \[Equal] 0, x[0] \[Equal] x0, \(x'\)[0] \[Equal] dx0}, x[t], t]\)}], "Input"], Cell["Note the use of the == sign.", "Text"], Cell[TextData[{ "NDSolve[]", ":", StyleBox[" Same idea as before, only this evaluates numerically. The main \ difference is that in this case, you need to specify the limits of the \ variable to solve for. In this example, we find the solution for 0 < t < 4 \ .", FontWeight->"Plain"] }], "Text", FontWeight->"Bold"], Cell[BoxData[{ \(Remove["\"]\), "\[IndentingNewLine]", \(\({x0, \ dx0} = {1, 2};\)\), "\[IndentingNewLine]", \(NDSolve[{\(x''\)[t] + 4 x[t] \[Equal] 0, x[0] \[Equal] x0, \(x'\)[0] \[Equal] dx0}, x[t], {t, 0, 4}]\)}], "Input"], Cell[TextData[{ StyleBox["Simplify[] ", FontWeight->"Bold"], "and ", StyleBox["FullSimplify[]", FontWeight->"Bold"], ". Two of the most handy tools you'll ever come across. So you've tried \ testing someting for equality and got a screen full of junk instead of \"True\ \"? Try simplifying." }], "Text"], Cell[BoxData[ \(Simplify[x^2\ + 2 x\ + \ 1]\)], "Input"], Cell[BoxData[ \(\(\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\)\)], "Input"], Cell[TextData[StyleBox["Things that will help you out: ", FontWeight->"Bold"]], "Subsubtitle"], Cell[TextData[{ "If you want help inputting functions, ", StyleBox["Mathematica", FontSlant->"Italic"], " offers a handy graphical utility. You can enable it by going to \ File...Palettes...Basic Input. This tool bar comes in handy for composing \ mathematical expressions. However, there are some keyboard shortcuts that \ you can do too. " }], "Text"], Cell["\<\ Most convenient of all is the escape key. If you try (ESC) + \ letter + (ESC), it will give you the greek equivalent of the letter you \ wrote. \ \>", "Text"], Cell["\<\ The second most helpful is, when beginning a new cell group, (ATL) \ + 7 turns it into a text group. This is handy for writing comments for the \ TA, or putting your name at the top of the paper, and so on.\ \>", "Text"], Cell["\<\ Other keyboard shortcuts are available in the online help. Look \ under \"Other Information\" and go to 2D Expression Input.\ \>", "Text", FontSlant->"Italic"], Cell["\<\ Ok. Those are the basics. Are you ready to try some for yourself? Go on to \ worksheet 1... (Don't hand this worksheet in. This one was just for refrence and example \ purposes.)\ \>", "Text"] }, FrontEndVersion->"4.0 for X", ScreenRectangle->{{0, 1024}, {0, 768}}, CellGrouping->Manual, WindowSize->{520, 600}, WindowMargins->{{237, Automatic}, {Automatic, 59}} ] (*********************************************************************** 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[1717, 49, 97, 2, 32, "Text"], Cell[1817, 53, 47, 4, 68, "Text"], Cell[1867, 59, 1368, 41, 248, "Text"], Cell[CellGroupData[{ Cell[3260, 104, 780, 19, 141, "Text"], Cell[4043, 125, 262, 7, 50, "Text"], Cell[4308, 134, 183, 3, 59, "Input"], Cell[4494, 139, 307, 5, 86, "Text"], Cell[4804, 146, 56, 1, 27, "Input"], Cell[4863, 149, 778, 13, 158, "Text"], Cell[5644, 164, 180, 3, 43, "Input"] }, Open ]], Cell[5839, 170, 16, 0, 32, "Text"], Cell[CellGroupData[{ Cell[5880, 174, 542, 17, 105, "Text"], Cell[6425, 193, 112, 2, 43, "Input"], Cell[6540, 197, 107, 4, 50, "Text"], Cell[6650, 203, 89, 2, 43, "Input"], Cell[6742, 207, 141, 3, 50, "Text"], Cell[6886, 212, 222, 4, 75, "Input"] }, Open ]], Cell[7123, 219, 16, 0, 32, "Text"], Cell[CellGroupData[{ Cell[7164, 223, 819, 26, 105, "Text"], Cell[7986, 251, 89, 2, 43, "Input"], Cell[8078, 255, 132, 3, 50, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[8247, 263, 367, 10, 141, "Text"], Cell[8617, 275, 260, 6, 98, "Input"] }, Open ]], Cell[8892, 284, 25, 3, 50, "Text"], Cell[CellGroupData[{ Cell[8942, 291, 264, 8, 69, "Text"], Cell[9209, 301, 46, 1, 27, "Input"], Cell[9258, 304, 73, 0, 32, "Text"], Cell[9334, 306, 50, 1, 27, "Input"], Cell[9387, 309, 71, 0, 32, "Text"], Cell[9461, 311, 61, 1, 27, "Input"], Cell[9525, 314, 355, 10, 68, "Text"] }, Open ]], Cell[9895, 327, 25, 3, 50, "Text"], Cell[9923, 332, 344, 12, 69, "Text"], Cell[10270, 346, 86, 1, 45, "Input"], Cell[10359, 349, 57, 0, 32, "Text"], Cell[10419, 351, 155, 4, 43, "Input"], Cell[10577, 357, 277, 8, 159, "Text"], Cell[10857, 367, 234, 4, 75, "Input"], Cell[11094, 373, 329, 8, 104, "Text"], Cell[11426, 383, 555, 17, 87, "Text"], Cell[11984, 402, 55, 1, 27, "Input"], Cell[12042, 405, 186, 4, 50, "Text"], Cell[12231, 411, 604, 14, 225, "Text"], Cell[12838, 427, 46, 1, 27, "Input"], Cell[12887, 430, 254, 5, 68, "Text"], Cell[13144, 437, 129, 3, 57, "Subtitle"], Cell[13276, 442, 143, 5, 32, "Text"], Cell[13422, 449, 78, 2, 43, "Input"], Cell[13503, 453, 161, 7, 32, "Text"], Cell[13667, 462, 74, 1, 27, "Input"], Cell[13744, 465, 119, 4, 32, "Text"], Cell[13866, 471, 185, 3, 43, "Input"], Cell[14054, 476, 172, 5, 32, "Text"], Cell[14229, 483, 67, 1, 27, "Input"], Cell[14299, 486, 277, 6, 68, "Text"], Cell[14579, 494, 251, 4, 75, "Input"], Cell[14833, 500, 44, 0, 32, "Text"], Cell[14880, 502, 332, 9, 68, "Text"], Cell[15215, 513, 267, 5, 75, "Input"], Cell[15485, 520, 322, 9, 68, "Text"], Cell[15810, 531, 63, 1, 27, "Input"], Cell[15876, 534, 83, 1, 59, "Input"], Cell[15962, 537, 96, 1, 53, "Subsubtitle"], Cell[16061, 540, 367, 8, 86, "Text"], Cell[16431, 550, 170, 4, 50, "Text"], Cell[16604, 556, 231, 4, 68, "Text"], Cell[16838, 562, 173, 4, 50, "Text"], Cell[17014, 568, 207, 7, 86, "Text"] } ] *) (*********************************************************************** End of Mathematica Notebook file. ***********************************************************************)