(* Content-type: application/mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 6.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 145, 7] NotebookDataLength[ 56207, 2072] NotebookOptionsPosition[ 49500, 1852] NotebookOutlinePosition[ 50620, 1889] CellTagsIndexPosition[ 50577, 1886] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell[TextData[StyleBox["Tutorial 03\nSymbols and Functions", FontColor->RGBColor[1, 0, 0]]], "Title", ImageRegion->{{0, 1}, {0, 1}}], Cell[TextData[StyleBox["Copyright \[Copyright] 2011 by Bill Titus\nCarleton \ College,\nDepartment of Physics and Astronomy\nNorthfield Minnesota \ 55057-4025\nDecember 01, 2011", FontWeight->"Plain", FontColor->RGBColor[1, 0, 0]]], "Subsubtitle", CellChangeTimes->{{3.530025425275792*^9, 3.530025434617466*^9}, 3.5300289599005203`*^9, 3.5308158907422953`*^9}, ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Bold"], Cell[CellGroupData[{ Cell[TextData[StyleBox["Part 1 - Getting Started", FontColor->RGBColor[0, 0, 1]]], "Section", ImageRegion->{{0, 1}, {0, 1}}], Cell[TextData[StyleBox["Step 1. If the workshop folder is not on your \ desktop, locate the workshop folder that contains the tutorials and move the \ entire folder to your desktop.", FontFamily->"Helvetica Neue", FontWeight->"Plain"]], "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Times New Roman"], Cell[TextData[{ StyleBox["Step 2. Select File / Open from the ", FontFamily->"Helvetica Neue", FontWeight->"Plain"], StyleBox["Mathematica", FontFamily->"Helvetica Neue", FontWeight->"Plain", FontSlant->"Italic"], StyleBox[" menu and load the notebook Tutorial03.nb that's now located in \ the workshop folder on your desktop.", FontFamily->"Helvetica Neue", FontWeight->"Plain"] }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Times New Roman"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ StyleBox["Part 2 -", FontColor->RGBColor[0, 0, 1]], StyleBox[" ", FontSlant->"Italic", FontColor->RGBColor[0, 0, 1]], StyleBox["The Problem of Interest", FontColor->RGBColor[0, 0, 1]] }], "Section", ImageRegion->{{0, 1}, {0, 1}}], Cell[CellGroupData[{ Cell[TextData[{ "In this notebook, you'll solve the first part of the following problem that \ is taken from ", StyleBox["Mathematics: A Simple Tool for Geologists", FontSlant->"Italic"], " by David Waltham (Chapman & Hall, London, 1994, page 38)." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[TextData[{ "The rate of accumulation, ", StyleBox["p", FontSlant->"Italic"], ", of carbonate sediments on a reef is given approximately by ", StyleBox["p", FontSlant->"Italic"], " = ", Cell[BoxData[ FormBox[ RowBox[{ FormBox[ SubscriptBox["p", "0"], TraditionalForm], " ", SuperscriptBox["\[ExponentialE]", RowBox[{ RowBox[{"-", "z"}], "/", SubscriptBox["z", "0"]}]]}], TraditionalForm]]], ", where ", Cell[BoxData[ FormBox[ SubscriptBox["p", "0"], TraditionalForm]]], " and ", Cell[BoxData[ FormBox[ SubscriptBox["z", "0"], TraditionalForm]]], " are constants and ", StyleBox["z", FontSlant->"Italic"], " is the depth below sea level.\n\n(i) Calculate ", StyleBox["p ", FontSlant->"Italic"], " at depths of 0.0, 2.0, 4.0, ... , 20.0 ", StyleBox["m", FontSlant->"Italic"], " if ", Cell[BoxData[ FormBox[ SubscriptBox["p", "0"], TraditionalForm]]], " = 3.0 ", StyleBox["m", FontSlant->"Italic"], " ", Cell[BoxData[ FormBox[ SuperscriptBox[ StyleBox["ky", FontSlant->"Italic"], RowBox[{"-", "1"}]], TraditionalForm]]], " and ", Cell[BoxData[ FormBox[ SubscriptBox["z", "0"], TraditionalForm]]], " = 20.0 ", StyleBox["m", FontSlant->"Italic"], ".\n(ii) Sketch the results.\n(iii) Give an interpretation for the \ constants ", Cell[BoxData[ FormBox[ SubscriptBox["p", "0"], TraditionalForm]]], " and ", Cell[BoxData[ FormBox[ SubscriptBox["z", "0"], TraditionalForm]]], "." }], "Text", ImageRegion->{{0, 1}, {0, 1}}] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ StyleBox["Part 3 - ", FontColor->RGBColor[0, 0, 1]], StyleBox["Mathematica", FontSlant->"Italic", FontColor->RGBColor[0, 0, 1]], StyleBox[" Constants and Help", FontColor->RGBColor[0, 0, 1]] }], "Section", ImageRegion->{{0, 1}, {0, 1}}], Cell[CellGroupData[{ Cell["Topics and Skills", "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue"], Cell[TextData[{ "1. ", StyleBox["Mathematica", FontSlant->"Italic"], " help using ?\n2. The Help Documentation (", StyleBox["HD", FontFamily->"Helvetica"], ")" }], "Text", ImageRegion->{{0, 1}, {0, 1}}] }, Open ]], Cell[TextData[{ "Step 1. In doing this calculation, you're going to need to have the value \ of the exponential constant ", StyleBox["E", FontFamily->"Courier"], ". Type ", StyleBox["?E", FontFamily->"Courier"], " in the cell below and see what happens." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[CellGroupData[{ Cell["Comment 1", "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[TextData[{ "1. The symbol ", StyleBox["?", FontFamily->"Courier"], " is your friend. It's an extremely useful ", StyleBox["Mathematica", FontSlant->"Italic"], " command and gives help on ", StyleBox["Mathematica", FontSlant->"Italic"], " and user-defined symbols and functions." }], "Text", ImageRegion->{{0, 1}, {0, 1}}] }, Open ]], Cell[TextData[{ "Step 2. See what happens if you click on the blue ", StyleBox[" >>", FontColor->RGBColor[0, 0, 1]], " symbol at the end of in the output cell associated with ", StyleBox["?E", FontFamily->"Courier", FontWeight->"Bold"], "." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[CellGroupData[{ Cell["Comment 2", "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[TextData[{ "1. When you clicked on ", StyleBox[">>", FontColor->RGBColor[0, 0, 1]], ", you open up ", StyleBox["Mathematica's", FontSlant->"Italic"], " Help Documentation (", StyleBox["HD", FontFamily->"Helvetica"], ") that contains detailed information on the symbol ", StyleBox["E", FontFamily->"Courier", FontWeight->"Bold"], ", including more information, examples and tutorials." }], "Text", CellChangeTimes->{{3.53002589065236*^9, 3.530025896082025*^9}}, ImageRegion->{{0, 1}, {0, 1}}] }, Open ]], Cell[TextData[{ "Step 3. While you're in the ", StyleBox["HD", FontWeight->"Plain"], " for ", StyleBox["?E", FontFamily->"Courier", FontWeight->"Bold"], ", open up ", StyleBox["Applications", FontWeight->"Plain"], " by clicking on the nearby triangle and read through the examples given. \ If you want, you can even activate the cells in the example by pressing the ", StyleBox["(enter)", FontFamily->"Helvetica Neue Bold Condensed"], " key." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell["\<\ Step 4. Now try clicking on any of the blue text in the \"Tutorials\" \ section and see what happens. \ \>", "Subsection", FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[CellGroupData[{ Cell["Comment 4", "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell["\<\ 1. This latter operation will take you to other related documentation pages. 2. You can return to your original help page by using the back arrow in the \ upper left hand corner of the panel.\ \>", "Text"] }, Open ]], Cell[TextData[{ "Step 5. You can also get to the ", StyleBox["HD", FontWeight->"Plain"], " by selecting ", StyleBox["Help / Documentation Center ...", FontWeight->"Plain"], " from the ", StyleBox["Mathematica", FontSlant->"Italic"], " menu bar and using the search capabilities of the panel that comes up. \ Try this out by getting help on the symbol ", StyleBox["E", FontFamily->"Courier", FontWeight->"Bold"], "." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[TextData[{ "Step 6. As practice, get help on the three ", StyleBox["Mathematica", FontSlant->"Italic"], " constants: ", StyleBox["Pi", FontFamily->"Courier", FontWeight->"Bold"], ", ", StyleBox["Degree", FontFamily->"Courier", FontWeight->"Bold"], ", and ", StyleBox["I", FontFamily->"Courier", FontWeight->"Bold"], "." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[CellGroupData[{ Cell["Comment 6", "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[TextData[{ "1. ", StyleBox["Mathematica ", FontSlant->"Italic"], "uses letters (symbols) not only to define constants, but functions and \ other constructs within ", StyleBox["Mathematica", FontSlant->"Italic"], ". Just remember that any ", StyleBox["Mathematica", FontSlant->"Italic"], " defined quantity will start with a capital letter. Say this sentence to \ yourself at least 5 times a day for a week -- it's important." }], "Text"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[TextData[StyleBox["Part 4 - User-Defined Symbols", FontColor->RGBColor[0, 0, 1]]], "Section", ImageRegion->{{0, 1}, {0, 1}}], Cell[CellGroupData[{ Cell["Topics and Skills", "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[TextData[{ "1. Using symbols for calculations\n2. Immediate assignment with ", StyleBox["Set[]", FontFamily->"Courier"], "\n3. The \"context\" for a symbol\n4. Multiple inputs in a single cell\n\ 5. A semicolon to suppress output" }], "Text", ImageRegion->{{0, 1}, {0, 1}}] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Step 1. Now you're going to do the sediment calculations using your own \ symbols. Type in the following code in a new cell below, and press the ", StyleBox["(enter)", FontFamily->"Helvetica Neue Bold Condensed", FontWeight->"Plain"], " key each time you have typed in a single line." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell["\<\ \tp0 = 3 \tz0 = 20 \tz = 2.0 \tp = p0*E^(-z/z0)\ \>", "Text", FontFamily->"Courier", FontWeight->"Bold"] }, Open ]], Cell[CellGroupData[{ Cell["Comment 1", "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[TextData[{ "1. When you type in a symbol, ", StyleBox["Mathematica", FontSlant->"Italic"], " will display it in", StyleBox[" ", FontWeight->"Bold"], StyleBox["blue", FontWeight->"Bold", FontColor->RGBColor[0, 0, 1]], ". But, as soon as you evaluate the symbol, the symbol becomes ", StyleBox["black", FontWeight->"Bold"], ". This convention allows you to scan your notebook for any unevaluated \ symbols.\n2. Note that all the inputs and outputs are in separate cells.\n3. \ Symbols are used to stand for quantities, including numbers, equations, \ expressions, and even collections of other symbols. They're used to make \ your calculations clear and flexible, and to help you organize your results \ and your notebook. \n4. Remember, since ", StyleBox["Mathematica", FontSlant->"Italic"], " starts its symbols with capital letters, it's best to start yours with \ lowercase letters. That way you avoid any possibility of conflicting with ", StyleBox["Mathematica", FontSlant->"Italic"], " defined quantities.\n5. The equal sign (also called ", StyleBox["Set[]", FontFamily->"Courier"], ") is an immediate assignment. For example, as soon as you enter the \ expressions for ", StyleBox["p0", FontFamily->"Courier"], " and ", StyleBox["z0 ", FontFamily->"Courier"], "on the right hand side of the equal sign, the symbols ", StyleBox["p0", FontFamily->"Courier"], " and ", StyleBox["z0", FontFamily->"Courier"], " are assigned those expressions.\n6. I don't use white spaces when I type \ in equations. ", StyleBox["Mathematica", FontSlant->"Italic"], " does a very good job of formatting equations so that they're very readable \ without your white spaces present." }], "Text", CellChangeTimes->{{3.530026065851655*^9, 3.530026066858386*^9}}, ImageRegion->{{0, 1}, {0, 1}}] }, Open ]], Cell[TextData[{ "Step 2. Type ", StyleBox["p0", FontFamily->"Courier", FontWeight->"Bold"], ", ", StyleBox["z0", FontFamily->"Courier", FontWeight->"Bold"], ", ", StyleBox["z", FontFamily->"Courier", FontWeight->"Bold"], ", and ", StyleBox["p", FontFamily->"Courier", FontWeight->"Bold"], " on separate lines, each followed by ", StyleBox["(enter)", FontFamily->"Helvetica Neue Bold Condensed", FontWeight->"Plain"], ", to confirm that the symbols have the values you entered." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[TextData[{ "Step 3. You can also confirm the values of your symbols using the ", StyleBox["Mathematica", FontSlant->"Italic"], " help command ", StyleBox["?", FontFamily->"Courier", FontWeight->"Bold"], ". Type ", StyleBox["?p", FontFamily->"Courier", FontWeight->"Bold"], " in the cell below and see what happens." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[CellGroupData[{ Cell["Comment 3", "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[TextData[{ "1. The word ", StyleBox["Global`", FontFamily->"Courier"], " signifies the \"context\" where your symbol is stored. For example, the \ full name of the symbol ", StyleBox["p", FontFamily->"Courier"], ", as far a ", StyleBox["Mathematica", FontSlant->"Italic"], " is concerned, is ", StyleBox["Global`p", FontFamily->"Courier"], ". Symbols may be stored in different contexts; the default context for \ user defined symbols is ", StyleBox["Global`", FontFamily->"Courier"], ". Symbols ", StyleBox["Mathematica", FontSlant->"Italic"], " defines are stored in the context ", StyleBox["System`", FontFamily->"Courier"], ". I find it useful to think of a context as a folder where something is \ kept." }], "Text", ImageRegion->{{0, 1}, {0, 1}}] }, Open ]], Cell[TextData[{ "Step 4. Repeat Step 2, but this time type in the symbols in the same cell, \ but with the symbols on different lines. Use the ", StyleBox["(return)", FontFamily->"Helvetica Neue Bold Condensed", FontWeight->"Plain"], " key to produce line breaks." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[CellGroupData[{ Cell["Comment 4", "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[TextData[{ "1. Typing all of your symbols in one cell allows you to evaluate all the \ symbols by only pressing the ", StyleBox["(enter", FontFamily->"Helvetica Neue Bold Condensed"], StyleBox[") ", FontFamily->"Helvetica"], "key once.\n2. Note, however, that the output still occurs on four separate \ cells." }], "Text", ImageRegion->{{0, 1}, {0, 1}}] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Step 5. In your calculation, there's no doubt to the numerical values of ", StyleBox["p0", FontFamily->"Courier", FontWeight->"Bold"], ", ", StyleBox["z0", FontFamily->"Courier", FontWeight->"Bold"], ", and ", StyleBox["z", FontFamily->"Courier", FontWeight->"Bold"], ". Thus you might not want to echo these values back to the screen. But \ you really do want to know the numerical results for ", StyleBox["p", FontFamily->"Courier", FontWeight->"Bold"], ". You can suppress the output from a line by putting a semicolon at the \ end of the line. Activate the code below and observe that the only output \ that now appears is that associated with the symbol ", StyleBox["p", FontFamily->"Courier", FontWeight->"Bold"], "." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[BoxData[{ RowBox[{ RowBox[{"p0", "=", "3"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"z0", "=", "20"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"z", "=", "2.0"}], ";"}], "\[IndentingNewLine]", RowBox[{"p", "=", RowBox[{"p0", "*", RowBox[{"E", "^", RowBox[{"(", RowBox[{ RowBox[{"-", "z"}], "/", "z0"}], ")"}]}]}]}]}], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Comment 5", "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[TextData[{ "1. You now have a very compact way of doing your calculation. All you \ have to do is go back to your single cell, change the value for ", StyleBox["z", FontSlant->"Italic"], ", press the ", StyleBox["(enter)", FontFamily->"Helvetica Neue Bold Condensed"], StyleBox[" ", FontFamily->"Helvetica"], "key, and record the numerical value that pops out. However, you can do \ better if you use ", StyleBox["Mathematica", FontSlant->"Italic"], "'s capability for creating functions. This technique will be the focus of \ the next two sections." }], "Text", ImageRegion->{{0, 1}, {0, 1}}] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ StyleBox["Part 5 - ", FontColor->RGBColor[0, 0, 1]], StyleBox["Mathematica", FontSlant->"Italic", FontColor->RGBColor[0, 0, 1]], StyleBox[" Defined Functions", FontColor->RGBColor[0, 0, 1]] }], "Section", ImageRegion->{{0, 1}, {0, 1}}], Cell[CellGroupData[{ Cell["Topics and Skills", "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[TextData[{ "1. Notation for a function\n2. Some ", StyleBox["Mathematica", FontSlant->"Italic"], " functions: ", StyleBox["N[]", FontFamily->"Courier"], ", ", StyleBox["ScientificForm[]", FontFamily->"Courier"], ", ", StyleBox["Plus[]", FontFamily->"Courier"], ", ", StyleBox["Power[]", FontFamily->"Courier"], ", ", StyleBox["Times[]", FontFamily->"Courier"], ", ", StyleBox["Divide[]", FontFamily->"Courier"], ", ", StyleBox["FullForm[]", FontFamily->"Courier"], ", ", StyleBox["Exp[]", FontFamily->"Courier"], ", ", StyleBox["Sin[]", FontFamily->"Courier"], ", ", StyleBox["Cos[]", FontFamily->"Courier"], ", ", StyleBox["Tan[]", FontFamily->"Courier"], ", and ", StyleBox["Clear[]", FontFamily->"Courier"], "\n3. More on postfix notation" }], "Text", ImageRegion->{{0, 1}, {0, 1}}] }, Open ]], Cell[TextData[{ "Step 1. In ", StyleBox["Mathematica", FontSlant->"Italic"], ", a function consists of a symbol, followed by a set of square brackets, \ and arguments that you put inside the square brackets. For example, i", "n ", StyleBox["Tutorial01.nb", FontWeight->"Plain"], ", ", " you used the ", StyleBox["Mathematica", FontSlant->"Italic"], " function ", StyleBox["N[]", FontFamily->"Courier", FontWeight->"Bold"], " to find the numerical values of rational numbers. In a single cell \ below, type in, on separate lines, ", StyleBox["N[2/3]", FontFamily->"Courier", FontWeight->"Bold"], ", ", StyleBox["N[2/3,50]", FontFamily->"Courier", FontWeight->"Bold"], ", ", StyleBox["N[E,50]", FontFamily->"Courier", FontWeight->"Bold"], ", and ", StyleBox["N[\[Pi],50]", FontFamily->"Courier", FontWeight->"Bold"], StyleBox[" ", FontFamily->"Courier"], "and then press the ", StyleBox[" ", FontFamily->"Helvetica"], StyleBox["(enter)", FontFamily->"Helvetica Neue Bold Condensed", FontWeight->"Plain"], " key." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[CellGroupData[{ Cell["Comment 1", "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[TextData[{ "1. There are over two thousand built-in ", StyleBox["Mathematica", FontSlant->"Italic"], " functions, many of which you'll never use.\n2. In \"standard\" notation, \ a function comes with a \"head\", which is the symbol naming the function, \ and square brackets, which are used to contain the argument(s) of the \ function, where multiple arguments are separated by commas. ", StyleBox["Mathematica", FontSlant->"Italic"], " defined functions always start with capital letters; if they contain more \ than one word, each word is capitalized; abbreviations are usually not used \ unless they are standard ones. " }], "Text", CellChangeTimes->{{3.5300275873809032`*^9, 3.530027590058364*^9}, { 3.530028972076263*^9, 3.530028972954791*^9}}, ImageRegion->{{0, 1}, {0, 1}}] }, Open ]], Cell[TextData[{ "Step 2. Use the ", StyleBox["Mathematica", FontSlant->"Italic"], " help command ", StyleBox["?", FontFamily->"Courier", FontWeight->"Bold"], StyleBox[" ", FontFamily->"Courier"], " to find out information on the ", StyleBox["Mathematica", FontSlant->"Italic"], " function ", StyleBox["N[]", FontFamily->"Courier", FontWeight->"Bold"], ". Don't include the square brackets when you ask for ", StyleBox["Mathematica", FontSlant->"Italic"], " help, i.e., just type ", StyleBox["?N", FontFamily->"Courier", FontWeight->"Bold"], " ." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[TextData[{ "Step 3. Here are some ", StyleBox["Mathematica", FontSlant->"Italic"], " functions that you have already used: ", StyleBox["Plus[]", FontFamily->"Courier", FontWeight->"Bold"], ", ", StyleBox["Power[]", FontFamily->"Courier", FontWeight->"Bold"], ", ", StyleBox["Times[]", FontFamily->"Courier", FontWeight->"Bold"], ", ", StyleBox["Divide[]", FontFamily->"Courier", FontWeight->"Bold"], ", and ", StyleBox["ScientificForm[]", FontFamily->"Courier", FontWeight->"Bold"], ". Get ", StyleBox["Mathematica", FontSlant->"Italic"], " help on each of these functions and be sure you understand what they do." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[CellGroupData[{ Cell[TextData[{ "Step 4. To reinforce what the four functions, ", StyleBox["Plus[]", FontFamily->"Courier", FontWeight->"Bold"], ", ", StyleBox["Power[]", FontFamily->"Courier", FontWeight->"Bold"], ", ", StyleBox["Times[]", FontFamily->"Courier", FontWeight->"Bold"], ", and ", StyleBox[" ", FontFamily->"Courier"], StyleBox["Divide[]", FontFamily->"Courier", FontWeight->"Bold"], " do, activate the cell below." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[BoxData[{ RowBox[{"Plus", "[", RowBox[{"a", ",", "b"}], "]"}], "\[IndentingNewLine]", RowBox[{"Power", "[", RowBox[{"c", ",", "\[Alpha]"}], "]"}], "\[IndentingNewLine]", RowBox[{"Times", "[", RowBox[{"a", ",", "b", ",", "c"}], "]"}], "\[IndentingNewLine]", RowBox[{"Divide", "[", RowBox[{"a", ",", "b"}], "]"}]}], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Comment 4", "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[TextData[{ "1. Almost everything in ", StyleBox["Mathematica", FontSlant->"Italic"], " is coded in terms of functions that ", StyleBox["Mathematica", FontSlant->"Italic"], " calls \"expressions\". For example, when you type ", StyleBox["a + b", FontFamily->"Courier"], ", ", StyleBox["Mathematica", FontSlant->"Italic"], " really stores the information as the function ", StyleBox["Plus[a, b]", FontFamily->"Courier"], ". As a matter of fact, ", StyleBox["Mathematica", FontSlant->"Italic"], " would be quite happy if everyone in the world wrote ", StyleBox["a + b", FontFamily->"Courier"], " as ", StyleBox["Plus[a, b]", FontFamily->"Courier"], ". This notation makes absolute sense since addition is really a function \ that takes two numbers/symbols and gives you a particular number/symbol \ back." }], "Text", ImageRegion->{{0, 1}, {0, 1}}] }, Open ]], Cell[TextData[{ "Step 5. If you really want to know how ", StyleBox["Mathematica", FontSlant->"Italic"], " stores the code you type, you can use the ", StyleBox["Mathematica", FontSlant->"Italic"], " function ", StyleBox["FullForm[]", FontFamily->"Courier", FontWeight->"Bold"], ". Get help on this function and then apply", " the function to the equation ", Cell[BoxData[ FormBox[ RowBox[{"a", "-", SuperscriptBox["b", "c"]}], TraditionalForm]]], " ." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[CellGroupData[{ Cell["Comment 5", "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[TextData[{ "1. You'll find ", StyleBox[" FullForm[]", FontFamily->"Courier"], " useful if you need to find out a particular part of a result or equation. \ You'll see an example of this need in a later tutorial notebook." }], "Text", ImageRegion->{{0, 1}, {0, 1}}] }, Open ]], Cell[TextData[{ "Step 6. Get ", StyleBox["Mathematica", FontSlant->"Italic"], " help of the functions ", StyleBox["Exp[]", FontFamily->"Courier", FontWeight->"Bold"], ", ", StyleBox["Sin[]", FontFamily->"Courier", FontWeight->"Bold"], ", ", StyleBox["Cos[]", FontFamily->"Courier", FontWeight->"Bold"], ", ", StyleBox["Tan[]", FontFamily->"Courier", FontWeight->"Bold"], ", and ", StyleBox["Clear[]", FontFamily->"Courier", FontWeight->"Bold"], " and be sure you understand what these functions do." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[CellGroupData[{ Cell[TextData[{ "Step 7. To see an example of ", StyleBox["Clear[]", FontFamily->"Courier", FontWeight->"Bold"], StyleBox[" ", FontFamily->"Courier"], "in action, activate the cell below." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[BoxData[{"p", "\[IndentingNewLine]", RowBox[{"Clear", "[", "p", "]"}], "\[IndentingNewLine]", "p"}], "Input"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Step 8. ", StyleBox["Mathematica", FontSlant->"Italic"], " has several ways to apply a function to one or more variables. The way \ you have been applying functions is the most commonly used technique. \ However, sometimes it useful to apply a function after the fact, so to speak \ (this is the postfix notation you've used previously in the example with N[ \ ]). Look over the code below, activate the cell, and see if you understand \ what's happening." }], "Subsection", CellChangeTimes->{{3.530027681981583*^9, 3.530027693162621*^9}}, ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[BoxData[{ RowBox[{ RowBox[{"x", "=", RowBox[{"\[Pi]", "/", "3"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"y", "=", RowBox[{"3", "*", RowBox[{"Sin", "[", "x", "]"}], "*", RowBox[{"Exp", "[", RowBox[{"Cos", "[", "x", "]"}], "]"}]}]}], "\[IndentingNewLine]", RowBox[{"y", "//", "N"}], "\[IndentingNewLine]", RowBox[{"y", "//", RowBox[{ RowBox[{"N", "[", RowBox[{"#", ",", "50"}], "]"}], "&"}]}], "\[IndentingNewLine]", RowBox[{"y", "//", "Tan"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"y", "//", "Tan"}], "//", "N"}]}], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Comment 8", "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[TextData[{ "1. The application of a function after the fact is call the postfix \ notation. It consists of ", StyleBox[" //", FontFamily->"Courier"], " followed by the function you want to apply. If the function has only a \ single argument, you just need to include the head of the function. However, \ if the function has more than one argument, you must use", StyleBox[" #", FontFamily->"Courier"], " as the variable to which you are applying the function, and then \ terminate the function with the symbol ", StyleBox["&", FontFamily->"Courier"], ".\n2. One advantage of postfix notation is when you want to do something \ quickly to a result of a rather lengthy calculation you have already \ completed. In this case, all you have to do is tack the function you want to \ apply to the end of your calculation. You'll see applications of postfix \ notation in some of the later tutorial notebooks." }], "Text", ImageRegion->{{0, 1}, {0, 1}}] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[TextData[StyleBox["Part 6 - User-Defined Functions", FontColor->RGBColor[0, 0, 1]]], "Section", ImageRegion->{{0, 1}, {0, 1}}], Cell[CellGroupData[{ Cell["Topics and Skills", "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[TextData[{ "1. User-defined functions using ", StyleBox["Set[]", FontFamily->"Courier"], " and simple patterns\n2. User-defined functions using ", StyleBox["DelayedSet[]", FontFamily->"Courier"], " and simple patterns\n3. The ", StyleBox["Mathematica", FontSlant->"Italic"], " ", StyleBox["Table[] ", FontFamily->"Courier"], "command\n4. A little bit on lists" }], "Text", ImageRegion->{{0, 1}, {0, 1}}] }, Open ]], Cell[CellGroupData[{ Cell["Step 1. Reread the problem you want to solve.", "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[TextData[{ "The rate of accumulation, ", StyleBox["p", FontSlant->"Italic"], ", of carbonate sediments on a reef is given approximately by ", StyleBox["p", FontSlant->"Italic"], " = ", Cell[BoxData[ FormBox[ RowBox[{ FormBox[ SubscriptBox["p", "0"], TraditionalForm], " ", SuperscriptBox["\[ExponentialE]", RowBox[{ RowBox[{"-", "z"}], "/", SubscriptBox["z", "0"]}]]}], TraditionalForm]]], ", where ", Cell[BoxData[ FormBox[ SubscriptBox["p", "0"], TraditionalForm]]], " and ", Cell[BoxData[ FormBox[ SubscriptBox["z", "0"], TraditionalForm]]], " are constants and ", StyleBox["z", FontSlant->"Italic"], " is the depth below sea level.\n\n(i) Calculate ", StyleBox["p ", FontSlant->"Italic"], " at depths of 0.0, 2.0, 4.0, ... , 20.0 ", StyleBox["m", FontSlant->"Italic"], " if ", Cell[BoxData[ FormBox[ SubscriptBox["p", "0"], TraditionalForm]]], " = 3.0 ", StyleBox["m ", FontSlant->"Italic"], Cell[BoxData[ FormBox[ SuperscriptBox[ StyleBox["ky", FontSlant->"Italic"], RowBox[{"-", "1"}]], TraditionalForm]]], " and ", Cell[BoxData[ FormBox[ SubscriptBox["z", "0"], TraditionalForm]]], " = 20.0 ", StyleBox["m", FontSlant->"Italic"], ".\n(ii) Sketch the results.\n(iii) Give an interpretation for the \ constants ", Cell[BoxData[ FormBox[ SubscriptBox["p", "0"], TraditionalForm]]], " and ", Cell[BoxData[ FormBox[ SubscriptBox["z", "0"], TraditionalForm]]], "." }], "Text", ImageRegion->{{0, 1}, {0, 1}}] }, Open ]], Cell[CellGroupData[{ Cell["\<\ Step 2. Activate the code below that finds the numerical solution to the \ problem using symbols.\ \>", "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[BoxData[{ RowBox[{ RowBox[{"p0", "=", "3"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"z0", "=", "20"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"z", "=", "2.0"}], ";"}], "\[IndentingNewLine]", RowBox[{"p", "=", RowBox[{"p0", "*", RowBox[{"E", "^", RowBox[{"(", RowBox[{ RowBox[{"-", "z"}], "/", "z0"}], ")"}]}]}]}]}], "Input"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Step 3. You're now going to define your own function ", StyleBox["p[z]", FontFamily->"Courier", FontWeight->"Bold"], " such that given a value of ", StyleBox["z", FontFamily->"Courier", FontWeight->"Bold"], ", your function will tell you the value of ", StyleBox["p", FontFamily->"Courier", FontWeight->"Bold"], " . To do so, look over the code below and enter the results. Try out your \ function with the value ", StyleBox["z", FontSlant->"Italic"], " = 4.0 and ", StyleBox["z", FontSlant->"Italic"], " = ", StyleBox["s", FontSlant->"Italic"], ", where ", StyleBox["s", FontSlant->"Italic"], " is an arbitrary symbol.", StyleBox[" ", FontFamily->"Courier"], "i.e., type in ", StyleBox["p[4.0]", FontFamily->"Courier", FontWeight->"Bold"], " and ", StyleBox["p[s]", FontFamily->"Courier", FontWeight->"Bold"], " and enter the results." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[BoxData[{ RowBox[{"Clear", "[", RowBox[{"p", ",", "z"}], "]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"p0", "=", "3.0"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"z0", "=", "2.0"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"p", "[", "z_", "]"}], "=", RowBox[{"p0", "*", RowBox[{"Exp", "[", RowBox[{ RowBox[{"-", "z"}], "/", "z0"}], "]"}]}]}]}], "Input", CellChangeTimes->{{3.530028573392931*^9, 3.5300285766923428`*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["Comment 3", "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[TextData[{ "1. Note that by defining the function ", StyleBox["p", FontSlant->"Italic"], "[", StyleBox["z", FontSlant->"Italic"], "], you can calculate ", StyleBox["p", FontSlant->"Italic"], "[", StyleBox["z", FontSlant->"Italic"], "] anywhere in your notebook. You don't have to go back to the original \ cell that defined the function as you would with the original symbol version \ of the calculation given in Step 2.\n2. The ", StyleBox["Clear[]", FontFamily->"Courier"], " function makes sure all your function and variables are undefined at the \ time of your definition. Many times you can get away without including ", StyleBox["Clear[]", FontFamily->"Courier"], " in your code, but sometimes you can get into problems. Before any \ function definition, I always include ", StyleBox["Clear[]", FontFamily->"Courier"], " with arguments corresponding to all the variables I'm plan to use in the \ function definition as well as the name of the function. It's better to be \ safe than sorry, and it does help you focus on the variables you need in \ defining your function.\n3. The underscore (also called a \"blank\") implies \ that ", StyleBox["z", FontFamily->"Courier"], " is the argument of the function whose name is ", StyleBox["p", FontFamily->"Courier"], " . Anything put into this slot will replace the corresponding symbol on \ the right hand side of the function definition. The combination of a symbol \ and an underscore, like ", StyleBox["z_", FontFamily->"Courier"], ", is called a simple pattern.\n4. Be careful with underscores. In a \ function definition, underscores must appear on the left hand side of the \ assignment statement and only on that side. A common error is to forget to \ put in the underscore. ", StyleBox["Mathematica", FontSlant->"Italic"], " will let you get away with this since the expression without an underscore \ is a valid construct, although it only works for the explicit symbol you put \ in the square brackets on the left hand side of the defining equation.\n5. \ Note the way in which ", StyleBox["Mathematica", FontSlant->"Italic"], " outputs the symbol for ", StyleBox["E", FontFamily->"Courier"], ". That symbol \[ExponentialE] is located on the ", StyleBox["Basic Math Assistant Palette", FontFamily->"Helvetica Neue"], " and you can easily insert that symbol into your code using the palette." }], "Text", CellChangeTimes->{{3.5300285998426323`*^9, 3.530028602002335*^9}}, ImageRegion->{{0, 1}, {0, 1}}] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Step 4. To see the problem that's created by not putting an underscore in \ the argument on the left hand side of the defining equation for ", StyleBox["p[z]", FontFamily->"Courier", FontWeight->"Bold"], ", activate the code below and then find ", StyleBox["pp[4.0]", FontFamily->"Courier", FontWeight->"Bold"], ", ", StyleBox["pp[s]", FontFamily->"Courier", FontWeight->"Bold"], ", and ", StyleBox["pp[z]", FontFamily->"Courier", FontWeight->"Bold"], ". " }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[BoxData[{ RowBox[{"Clear", "[", RowBox[{"pp", ",", "z"}], "]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"p0", "=", "3.0"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"z0", "=", "2.0"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"pp", "[", "z", "]"}], "=", RowBox[{"p0", "*", RowBox[{"Exp", "[", RowBox[{ RowBox[{"-", "z"}], "/", "z0"}], "]"}]}]}]}], "Input", CellChangeTimes->{{3.530028689260861*^9, 3.530028689764616*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["Comment 4", "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[TextData[{ "1. Without the underscore, ", StyleBox["pp[]", FontFamily->"Courier"], " is only defined for the symbol ", StyleBox["z", FontFamily->"Courier"], ". On the other hand, because of the underscore in the definition of ", StyleBox["p[]", FontFamily->"Courier"], " in Step 3, ", StyleBox["p[]", FontFamily->"Courier"], " is defined for anything you want to put in there as an argument, i.e., \ ", StyleBox["p[CarletonCollege]", FontFamily->"Courier"], " is a perfectly well-defined quantity." }], "Text", CellChangeTimes->{{3.530028725972855*^9, 3.530028730114972*^9}}, ImageRegion->{{0, 1}, {0, 1}}] }, Open ]], Cell[TextData[{ "Step 5. Get ", StyleBox["Mathematica", FontSlant->"Italic"], " help on your two functions ", StyleBox[" ", FontFamily->"Courier"], StyleBox["p[]", FontFamily->"Courier", FontWeight->"Bold"], " and ", StyleBox["pp[]", FontFamily->"Courier", FontWeight->"Bold"], "." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[CellGroupData[{ Cell["Comment 5", "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[TextData[{ "1. If your function isn't doing what you want it to do, the first thing \ you might try is to get help on the function and see what ", StyleBox["Mathematica", FontSlant->"Italic"], " has stored for your function. Many times you'll be surprised at what you \ find and thus be able to detect your mistake. It's very easy to blame ", StyleBox["Mathematica", FontSlant->"Italic"], " for errors that occur. However, ", StyleBox["Mathematica", FontSlant->"Italic"], " just does what you tell it to do." }], "Text", ImageRegion->{{0, 1}, {0, 1}}] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Step 6. When defining a function, one of the things you must do is decide \ which of your quantities are constants and which are variables. For example, \ in your definition of ", StyleBox["p[]", FontFamily->"Courier", FontWeight->"Bold"], ", you choose ", StyleBox["p0", FontFamily->"Courier", FontWeight->"Bold"], " and ", StyleBox["z0", FontFamily->"Courier", FontWeight->"Bold"], " to be constants and ", StyleBox["z", FontFamily->"Courier", FontWeight->"Bold"], " to be the variable of interest. But suppose you want to vary ", StyleBox["p0", FontFamily->"Courier", FontWeight->"Bold"], " and ", StyleBox["z0", FontFamily->"Courier", FontWeight->"Bold"], " as well. You can easily do that by defining a function ", StyleBox["pNew[]", FontFamily->"Courier", FontWeight->"Bold"], " with three variables. Look at the code below, activate the cell, and \ then evaluate the function when ", Cell[BoxData[ FormBox[ SubscriptBox["p", "0"], TraditionalForm]]], " = 2.0, ", Cell[BoxData[ FormBox[ SubscriptBox["z", "0"], TraditionalForm]]], " = 4.0, and ", StyleBox["z", FontSlant->"Italic"], " = 2.5." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[BoxData[{ RowBox[{"Clear", "[", RowBox[{"pNew", ",", "p0", ",", "z0", ",", "z"}], "]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"pNew", "[", RowBox[{"p0_", ",", "z0_", ",", "z_"}], "]"}], "=", RowBox[{"p0", "*", RowBox[{"Exp", "[", RowBox[{ RowBox[{"-", "z"}], "/", "z0"}], "]"}]}]}]}], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Comment 6", "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell["\<\ 1. If you don't want to output the general form of your equation when you \ define it, just put a semicolon after the definition on the right hand side \ of the equation. The semicolon will suppress output. Try it out.\ \>", "Text", ImageRegion->{{0, 1}, {0, 1}}] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Step 7. There's one more symbol that is used to define functions, the \ symbol", StyleBox[" ", FontFamily->"Courier"], StyleBox[":=", FontFamily->"Courier", FontWeight->"Bold"], StyleBox[" ", FontWeight->"Bold"], " that is equivalent to the function", StyleBox[" ", FontFamily->"Courier"], StyleBox["SetDelayed[]", FontFamily->"Courier", FontWeight->"Bold"], ". Activate the code below and see if you can tell the difference between ", StyleBox["=", FontFamily->"Courier", FontWeight->"Bold"], " and ", StyleBox[":=", FontFamily->"Courier", FontWeight->"Bold"], StyleBox[" ", FontFamily->"Courier"], "." }], "Subsection", CellChangeTimes->{3.5300288044685497`*^9}, ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[BoxData[{ RowBox[{"Clear", "[", RowBox[{"pD", ",", "z"}], "]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"p0", "=", "3.0"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"z0", "=", "2.0"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"pD", "[", "z_", "]"}], ":=", RowBox[{"p0", "*", RowBox[{"Exp", "[", RowBox[{ RowBox[{"-", "z"}], "/", "z0"}], "]"}]}]}], "\[IndentingNewLine]", RowBox[{"?", "pD"}]}], "Input", CellChangeTimes->{3.53002882448752*^9}] }, Open ]], Cell[CellGroupData[{ Cell["Comment 7", "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[TextData[{ "1. Note that the two lines of code\n\n", StyleBox["\tp0 = 3.0;\n\tz0 = 2.0;", FontFamily->"Courier"], "\n\t\nare not needed in using ", StyleBox["SetDelayed[]", FontFamily->"Courier"], ". As a matter of fact, they only confuse the issue since they are not \ relevant to the function definition since ", StyleBox[":=", FontFamily->"Courier"], " is used.\n2. Basically ", StyleBox["SetDelayed[] ", FontFamily->"Courier"], "doesn't evaluate any of the symbols used in its definition until it's \ called. On the other hand, ", StyleBox["Set[]", FontFamily->"Courier"], " immediately evaluates any symbol that has a value, except for the \ variables listed in its argument.\n3. I usually use ", StyleBox["SetDelayed[]", FontFamily->"Courier"], " in defining functions unless there's a real good reason to use ", StyleBox["Set[]", FontFamily->"Courier"], ". The distinction between these two function will become clearer as you \ get more practice using ", StyleBox["Mathematica", FontSlant->"Italic"], ".\n4. Even though there is no semicolon at the end of the line defining \ ", StyleBox["pD[z]", FontFamily->"Courier"], ", ", StyleBox["Mathematica", FontSlant->"Italic"], " didn't echo the equation back to the screen as it would have for a ", StyleBox["Set[]", FontFamily->"Courier"], " definition." }], "Text", ImageRegion->{{0, 1}, {0, 1}}] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Step 8. Now that you have the function ", StyleBox["p[z", FontFamily->"Courier", FontWeight->"Bold"], StyleBox["] ", FontFamily->"Courier"], "defined, how do you evaluate it for a number of values for ", StyleBox["z", FontFamily->"Courier", FontWeight->"Bold"], " other than typing in each value separately? To do so, you're going to \ use the ", StyleBox["Mathematica", FontSlant->"Italic"], " function ", StyleBox["Table[]", FontFamily->"Courier", FontWeight->"Bold"], ". ", StyleBox["Mathematica", FontSlant->"Italic"], " help is a bit confusing with respect to this function, so first activate \ the code below and see if you can determine what ", StyleBox["Table[]", FontFamily->"Courier", FontWeight->"Bold"], " does." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[BoxData[{ RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{"2", "*", "i"}], "+", "1"}], ",", RowBox[{"{", RowBox[{"i", ",", "0", ",", "10"}], "}"}]}], "]"}], "\[IndentingNewLine]", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{"2", "*", "i"}], "+", "1"}], ",", RowBox[{"{", RowBox[{"i", ",", "0", ",", "10", ",", "2"}], "}"}]}], "]"}]}], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Comment 8", "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Times New Roman"], Cell[TextData[{ "1. Anytime you see curly brackets used in ", StyleBox["Mathematica", FontSlant->"Italic"], ", it's with respect to lists of objects like numbers, symbols, etc. In the \ ", StyleBox["Table[]", FontFamily->"Courier"], " example above, the output is in terms of a list of values calculated via \ the equation given as the first argument of ", StyleBox["Table[]", FontFamily->"Courier"], ". The second argument of ", StyleBox["Table[]", FontFamily->"Courier"], " is a list of three quantities in one case and four quantities in the \ other: the variable ", StyleBox["i", FontFamily->"Courier"], ", the starting value for ", StyleBox["i", FontFamily->"Courier"], ", the final value for", StyleBox[" i", FontFamily->"Courier"], ", and, if present, the increment between successive values for ", StyleBox["i", FontFamily->"Courier"], "." }], "Text", ImageRegion->{{0, 1}, {0, 1}}] }, Open ]], Cell[TextData[{ "Step 9. Get ", StyleBox["Mathematica", FontSlant->"Italic"], " help on ", StyleBox["Table[]", FontFamily->"Courier", FontWeight->"Bold"], StyleBox[" ", FontFamily->"Times"], " by using ", StyleBox[" ", FontFamily->"Times"], StyleBox["?", FontFamily->"Courier", FontWeight->"Bold"], StyleBox[" ", FontFamily->"Times"], "and see if the explanation makes sense. Now go to the ", StyleBox["HD", FontWeight->"Plain"], " by selecting ", StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox[">>", FontWeight->"Plain", FontColor->RGBColor[0, 0, 1]], " and look through some of the examples given." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[TextData[{ "Step 10. Apply the ", StyleBox["Table[]", FontFamily->"Courier", FontWeight->"Bold"], " command to your function ", StyleBox["p[z]", FontFamily->"Courier", FontWeight->"Bold"], " to generate the values for ", StyleBox["p", FontSlant->"Italic"], " corresponding to ", StyleBox["z", FontSlant->"Italic"], " going from 0.0 to 20.0 in steps of 2.0." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[StyleBox["Part 7 - Save Your Notebook (OPTIONAL)", FontColor->RGBColor[0, 0, 1]]], "Section", ImageRegion->{{0, 1}, {0, 1}}], Cell[TextData[{ "Step 1. Delete all your output cell. Remember, to do this task, go to \ the menu bar and activate Cell", StyleBox[" / Delete All Output", FontWeight->"Plain"], ". A panel will come up asking whether you really want to do this or not. \ Press ", StyleBox["OK", FontWeight->"Plain"], " and the output cell disappear." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"], Cell[TextData[{ "Step 2. Save the notebook one last time, and quit ", StyleBox["Mathematica.", FontSlant->"Italic"] }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}, FontFamily->"Helvetica Neue", FontWeight->"Plain"] }, Open ]] }, Open ]] }, WindowToolbars->{}, WindowSize->{1232, 1236}, WindowMargins->{{157, Automatic}, {Automatic, 98}}, PrintingCopies->1, PrintingPageRange->{1, Automatic}, PageHeaders->{{Inherited, Inherited, Inherited}, {None, Inherited, None}}, PageFooters->{{Inherited, Inherited, Inherited}, {Inherited, Cell[ TextData[{ CounterBox["Page"]}], "PageNumber"], Inherited}}, PageHeaderLines->{Inherited, False}, PrintingOptions->{"PrintCellBrackets"->False, "PrintMultipleHorizontalPages"->False, "PrintRegistrationMarks"->True, "PrintingMargins"->54}, PrivateNotebookOptions->{"ColorPalette"->{RGBColor, -1}}, ShowSelection->True, ShowCellLabel->True, ShowCellTags->False, RenderingOptions->{"ObjectDithering"->True, "RasterDithering"->False}, Magnification:>FEPrivate`If[ FEPrivate`Equal[FEPrivate`$VersionNumber, 6.], 1.5, 1.5 Inherited], FrontEndVersion->"8.0 for Mac OS X x86 (32-bit, 64-bit Kernel) (February 23, \ 2011)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[567, 22, 134, 2, 185, "Title"], Cell[704, 26, 452, 9, 161, "Subsubtitle"], Cell[CellGroupData[{ Cell[1181, 39, 126, 2, 100, "Section"], Cell[1310, 43, 317, 6, 80, "Subsection"], Cell[1630, 51, 483, 14, 66, "Subsection"] }, Open ]], Cell[CellGroupData[{ Cell[2150, 70, 257, 9, 100, "Section"], Cell[CellGroupData[{ Cell[2432, 83, 357, 9, 80, "Subsection"], Cell[2792, 94, 1585, 67, 162, "Text"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[4426, 167, 264, 9, 100, "Section"], Cell[CellGroupData[{ Cell[4715, 180, 102, 2, 55, "Subsection"], Cell[4820, 184, 215, 9, 62, "Text"] }, Open ]], Cell[5050, 196, 373, 12, 81, "Subsection"], Cell[CellGroupData[{ Cell[5448, 212, 116, 3, 40, "Subsection"], Cell[5567, 217, 344, 12, 62, "Text"] }, Open ]], Cell[5926, 232, 358, 12, 55, "Subsection"], Cell[CellGroupData[{ Cell[6309, 248, 116, 3, 40, "Subsection"], Cell[6428, 253, 522, 17, 62, "Text"] }, Open ]], Cell[6965, 273, 574, 19, 82, "Subsection"], Cell[7542, 294, 188, 5, 60, "Subsection"], Cell[CellGroupData[{ Cell[7755, 303, 116, 3, 60, "Subsection"], Cell[7874, 308, 217, 4, 93, "Text"] }, Open ]], Cell[8106, 315, 545, 19, 121, "Subsection"], Cell[8654, 336, 456, 20, 61, "Subsection"], Cell[CellGroupData[{ Cell[9135, 360, 116, 3, 60, "Subsection"], Cell[9254, 365, 459, 13, 93, "Text"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[9762, 384, 131, 2, 150, "Section"], Cell[CellGroupData[{ Cell[9918, 390, 124, 3, 81, "Subsection"], Cell[10045, 395, 290, 7, 193, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[10372, 407, 415, 10, 121, "Subsection"], Cell[10790, 419, 116, 7, 160, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[10943, 431, 116, 3, 81, "Subsection"], Cell[11062, 436, 1852, 49, 396, "Text"] }, Open ]], Cell[12929, 488, 620, 25, 121, "Subsection"], Cell[13552, 515, 445, 16, 100, "Subsection"], Cell[CellGroupData[{ Cell[14022, 535, 116, 3, 60, "Subsection"], Cell[14141, 540, 800, 27, 126, "Text"] }, Open ]], Cell[14956, 570, 378, 10, 121, "Subsection"], Cell[CellGroupData[{ Cell[15359, 584, 116, 3, 60, "Subsection"], Cell[15478, 589, 371, 10, 97, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[15886, 604, 887, 28, 201, "Subsection"], Cell[16776, 634, 382, 12, 165, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[17195, 651, 116, 3, 81, "Subsection"], Cell[17314, 656, 623, 17, 130, "Text"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[17986, 679, 263, 9, 150, "Section"], Cell[CellGroupData[{ Cell[18274, 692, 124, 3, 81, "Subsection"], Cell[18401, 697, 860, 42, 160, "Text"] }, Open ]], Cell[19276, 742, 1184, 46, 201, "Subsection"], Cell[CellGroupData[{ Cell[20485, 792, 116, 3, 60, "Subsection"], Cell[20604, 797, 802, 16, 160, "Text"] }, Open ]], Cell[21421, 816, 689, 28, 123, "Subsection"], Cell[22113, 846, 769, 31, 139, "Subsection"], Cell[CellGroupData[{ Cell[22907, 881, 550, 23, 100, "Subsection"], Cell[23460, 906, 346, 8, 165, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[23843, 919, 116, 3, 81, "Subsection"], Cell[23962, 924, 897, 29, 160, "Text"] }, Open ]], Cell[24874, 956, 587, 21, 121, "Subsection"], Cell[CellGroupData[{ Cell[25486, 981, 116, 3, 60, "Subsection"], Cell[25605, 986, 278, 7, 93, "Text"] }, Open ]], Cell[25898, 996, 646, 28, 121, "Subsection"], Cell[CellGroupData[{ Cell[26569, 1028, 304, 11, 61, "Subsection"], Cell[26876, 1041, 116, 1, 130, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[27029, 1047, 652, 14, 198, "Subsection"], Cell[27684, 1063, 579, 16, 234, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[28300, 1084, 116, 3, 81, "Subsection"], Cell[28419, 1089, 976, 20, 228, "Text"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[29444, 1115, 133, 2, 150, "Section"], Cell[CellGroupData[{ Cell[29602, 1121, 124, 3, 81, "Subsection"], Cell[29729, 1126, 435, 15, 160, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[30201, 1146, 153, 3, 81, "Subsection"], Cell[30357, 1151, 1580, 66, 243, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[31974, 1222, 213, 6, 81, "Subsection"], Cell[32190, 1230, 382, 12, 165, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[32609, 1247, 1029, 41, 162, "Subsection"], Cell[33641, 1290, 474, 13, 166, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[34152, 1308, 116, 3, 81, "Subsection"], Cell[34271, 1313, 2564, 62, 537, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[36872, 1380, 610, 22, 121, "Subsection"], Cell[37485, 1404, 473, 13, 165, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[37995, 1422, 116, 3, 81, "Subsection"], Cell[38114, 1427, 648, 20, 126, "Text"] }, Open ]], Cell[38777, 1450, 407, 18, 82, "Subsection"], Cell[CellGroupData[{ Cell[39209, 1472, 116, 3, 60, "Subsection"], Cell[39328, 1477, 574, 14, 126, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[39939, 1496, 1304, 47, 241, "Subsection"], Cell[41246, 1545, 333, 10, 97, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[41616, 1560, 116, 3, 81, "Subsection"], Cell[41735, 1565, 277, 5, 93, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[42049, 1575, 812, 31, 123, "Subsection"], Cell[42864, 1608, 496, 14, 201, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[43397, 1627, 116, 3, 81, "Subsection"], Cell[43516, 1632, 1423, 41, 463, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[44976, 1678, 894, 31, 201, "Subsection"], Cell[45873, 1711, 393, 12, 96, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[46303, 1728, 95, 2, 81, "Subsection"], Cell[46401, 1732, 938, 30, 160, "Text"] }, Open ]], Cell[47354, 1765, 757, 31, 121, "Subsection"], Cell[48114, 1798, 500, 19, 100, "Subsection"] }, Open ]], Cell[CellGroupData[{ Cell[48651, 1822, 140, 2, 150, "Section"], Cell[48794, 1826, 452, 13, 157, "Subsection"], Cell[49249, 1841, 223, 7, 60, "Subsection"] }, Open ]] }, Open ]] } ] *) (* End of internal cache information *)