(************** 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[ 21368, 786]*) (*NotebookOutlinePosition[ 22427, 826]*) (* CellTagsIndexPosition[ 22306, 818]*) (*WindowFrame->Normal*) Notebook[{ Cell[TextData[{ "Introduction to ", StyleBox["Mathematica \[MathematicaIcon]", FontSlant->"Italic"] }], "Title"], Cell[TextData[{ "5. Programming in ", StyleBox["Mathematica", FontSlant->"Italic"] }], "Subtitle"], Cell["\<\ P. S. Cally, School of Mathematical Sciences, Monash \ University\ \>", "Author"], Cell[TextData[{ "We will turn off that annoying spelling warning ", StyleBox["Mathematica", FontSlant->"Italic"], " often gives. Note that this is set up as an \"Initialization Cell\", so \ it automatically runs when you fast start the kernel (after asking you). Go \ to Cell > CellProperties > InitializationCell to set these. They are marked \ by cell brackets featuring small vertical and diagonal lines in the top \ corner." }], "Text"], Cell[BoxData[ \(Off[General::"\"]\)], "Input", InitializationCell->True], Cell[CellGroupData[{ Cell["Compound Expressions", "Section"], Cell[TextData[{ "Unlike many programming languages, ", StyleBox["Mathematica", FontSlant->"Italic"], " programs do not normally consist of a structured set of lines, which may \ or may not need to be compiled. Rather, we set up a series of definitions. \ These can be in separate cells, or strung togeher as a single ", StyleBox["compound expression", FontWeight->"Bold"], ".\nHere is an example. Say we wanted to use the recurrence relation y(n)=a \ y(n-1)+y(n) with y(0)=0, y(1)=1, to find y(10). There are very many ways to \ do this. Here is one:" }], "Text"], Cell[BoxData[ \(y[0] = 0; y[1] = 1; y[n_] := a\ y[n - 1] + y[n - 2]; FullSimplify[y[10]]\)], "Input"], Cell["\<\ By using \";\" we have made a small \"program\". So, what's wrong \ with that? Well, nothing really, but it just leaves a lot of rubbish lying \ around \[Ellipsis]\ \>", "Text"], Cell[BoxData[ \(\(?y\)\)], "Input"], Cell["We need to tidy up:", "Text"], Cell[BoxData[ \(Clear[y]\)], "Input"], Cell[BoxData[ \(\(?y\)\)], "Input"] }, Closed]], Cell[CellGroupData[{ Cell["Modules", "Section"], Cell["\<\ A far neater way to do this is to use a Module. In this case, y is \ declared to be a local variable:\ \>", "Text"], Cell[BoxData[ \(m[a_, k_] := Module[{y, y0 = 0, y1 = 1}, y[0] = y0; y[1] = y1; y[n_] := a\ y[n - 1] + y[n - 2]; FullSimplify[y[k]]]\)], "Input"], Cell[BoxData[ \(m[a, 10]\)], "Input"], Cell[BoxData[ \(\(?y\)\)], "Input"], Cell["\<\ We see that y is unknown outside the module, which is what we want. \ Modules provide a convenient way to \"hide\" all the internal workings.\ \>", \ "Text"] }, Closed]], Cell[CellGroupData[{ Cell["Blocks", "Section"], Cell[TextData[{ "Blocks are very like modules. Indeed, the difference is rather subtle. ", StyleBox["As a rule of thumb, you should normally use Modules rather than \ Blocks. ", FontWeight->"Bold"], "For our recurrence relation example, Block behaves exactly like Module." }], "Text"], Cell[BoxData[ \(b[a_, k_] := Block[{y, y0 = 0, y1 = 1}, y[0] = y0; y[1] = y1; y[n_] := a\ y[n - 1] + y[n - 2]; FullSimplify[y[k]]]\)], "Input"], Cell[BoxData[ \(b[a, 10]\)], "Input"], Cell[BoxData[ \(\(?y\)\)], "Input"], Cell["\<\ However, this little example will illustrate an important \ difference:\ \>", "Text"], Cell[BoxData[ \(p = Sin[k]\)], "Input"], Cell[BoxData[ \(Block[{k = a}, k + p]\)], "Input"], Cell[BoxData[ \(Module[{k = a}, k + p]\)], "Input"], Cell["\<\ What has happened? Well, in Module the local variable k is actually \ given a different name internally:\ \>", "Text"], Cell[BoxData[ \(Module[{t}, t]\)], "Input"], Cell["\<\ This is how it keeps it's value private. The $n symbol is unique to \ each invokation of Module; so for example, this is what happens if we do it \ again\ \>", "Text"], Cell[BoxData[ \(Module[{t}, t]\)], "Input"], Cell["\<\ However, Block does not do this; it keeps the symbol t, but just \ changes its local value (if desired), resetting it to the global value at the \ end.\ \>", "Text"], Cell[BoxData[ \(Block[{t}, t]\)], "Input"], Cell["So, for example,", "Text"], Cell[BoxData[ \(a = 12; Block[{a = 3}, Print["\", a]]; a\)], "Input"], Cell[BoxData[ \(Clear[a]\)], "Input"] }, Closed]], Cell[CellGroupData[{ Cell["With", "Section"], Cell["\<\ With is rather like Module and Block again, but you cannot just \ declare a local variable without giving it a particular value. It is designed \ as a convenient way of assigning constants.\ \>", "Text"], Cell[BoxData[ \(With[{k = 3}, \((1.0 + k)\)\^2 + Sin[k] + Exp[k\^2]]\)], "Input"], Cell["This could alternatively be done like this:", "Text"], Cell[BoxData[ \(\((1.0 + k)\)\^2 + Sin[k] + Exp[k\^2] /. k \[Rule] 3\)], "Input"] }, Closed]], Cell[CellGroupData[{ Cell["\<\ Loops and Control Structures (if you must)\ \>", "Section"], Cell[TextData[{ "Does ", StyleBox["Mathematica", FontSlant->"Italic"], " have the do loops and other constructs of classical procedural languages \ such as FORTRAN or C? Yes indeed, but using them is a sign of a pretty poor \ ", StyleBox["Mathematica", FontSlant->"Italic"], " programmer. They tend to be both inelegant and slow. However, \ occasionally, they are useful, so let's have a quick look at a few of them." }], "Text"], Cell[CellGroupData[{ Cell["Do", "Subsection"], Cell["\<\ Here we use Do to add the first million integers (a rather silly \ exercise of course, as the answer is obvious):\ \>", "Text"], Cell[BoxData[ \(Timing[sum = 0; Do[sum += i, {i, 1000000}]; sum]\)], "Input"], Cell["but this is better", "Text"], Cell[BoxData[ \(Timing[Sum[i, {i, 1000000}]]\)], "Input"], Cell["and this is better still", "Text"], Cell[BoxData[ \(Timing[Plus @@ Range[1000000]]\)], "Input"], Cell["By the way, +=k adds k to a variable:", "Text"], Cell[BoxData[ \(n = 3; n += 5; n\)], "Input"], Cell["We could just as well have said n=n+5.", "Text"], Cell[BoxData[ \(sum =. ; n =. \)], "Input"] }, Closed]], Cell[CellGroupData[{ Cell["For and While", "Subsection"], Cell[TextData[{ "For is similar to Do, except that it does not prescribe a set numbver of \ loops, but rather tests to see when a stop criterion is satisfied. It takes \ the form ", StyleBox["For[", "MR"], StyleBox["start", "TI"], StyleBox[",", "MR"], " ", StyleBox["test", "TI"], StyleBox[",", "MR"], " ", StyleBox["incr", "TI"], StyleBox[",", "MR"], " ", StyleBox["body", "TI"], StyleBox["].", "MR"] }], "Text"], Cell[BoxData[ \(For[i = 1, \ i < 5, \ \(i++\), \ Print["\", i, \*"\"\<, \!\(i\^2\)=\>\"", i\^2]]\)], "Input", CellTags->"For"], Cell["By the way, i++ increases the value of i by 1.", "Text"], Cell[BoxData[ \(i =. \)], "Input"], Cell[TextData[{ "While takes the cut-down form ", StyleBox["While[", "MR"], StyleBox["test", "TI"], StyleBox[",", "MR"], " ", StyleBox["body", "TI"], StyleBox["]. ", "MR"], StyleBox["You need to work the iteration into ", "MR", FontFamily->"Times"], StyleBox["test", "MR", FontFamily->"Times", FontSlant->"Italic"], StyleBox[" or ", "MR", FontFamily->"Times"], StyleBox["body", "MR", FontFamily->"Times", FontSlant->"Italic"], StyleBox[". Here it's in the ", "MR", FontFamily->"Times"], StyleBox["test", "MR", FontFamily->"Times", FontSlant->"Italic"], StyleBox[".", "MR", FontFamily->"Times"] }], "Text"], Cell[BoxData[ \(nn = 10; While[\((nn = nn - 1)\) > 5, Print[nn]]\)], "Input", CellTags->"While"], Cell[BoxData[ \(nn =. \)], "Input"] }, Closed]], Cell[CellGroupData[{ Cell["Others", "Subsection"], Cell[TextData[{ "You might also like to check out Break, Throw, Return, Catch, Abort, Sow, \ Reap, \[Ellipsis] You should rarely need them. In fact, there are a few I've \ ", StyleBox["never", FontSlant->"Italic"], " used!" }], "Text"] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell["Compile", "Section"], Cell[TextData[{ "Here are three ways to make many iterations of the recurrence ", Cell[BoxData[ \(TraditionalForm\`t\_\(n + 1\) = 4 \(\(\( t\_n\)(1 - t\_n)\)\(.\)\(\ \)\)\)]], "The first uses Do, and is very slow." }], "Text"], Cell[BoxData[ \(fd[n_, x_] := Timing[Module[{t}, t = x; Do[t = 4 t \((1 - t)\), {n}]; t]]\)], "Input",\ CellTags->"Compile"], Cell["\<\ Use Timing to see how long it takes to do one million iterations.\ \ \>", "Text"], Cell[BoxData[ \(fd[1000000, .37]\)], "Input"], Cell[TextData[{ "Slow! But it can be speeded up greatly by ", StyleBox["compiling", FontSlant->"Italic"], " the function.", StyleBox[" ", FontSlant->"Italic"], "First, create a CompiledFunction" }], "Text"], Cell[BoxData[ \(fc = Compile[{{n, _Integer}, x}, Module[{t}, t = x; Do[t = 4 t \((1 - t)\), {n}]; t]]\)], "Input"], Cell[TextData[{ StyleBox["Mathematica", FontSlant->"Italic"], " has turned fd into much more efficient code, in part by assuming that x \ (and hence t) is a real number, whereas fd has to admit the possibility that \ x is say a list, or a variable that hasn't been given a numeric value, etc. \ That makes for far less efficient machine code. So, let's see how the \ compiled code performs:" }], "Text"], Cell[BoxData[ \(Timing[fc[1000000, 0.37]]\)], "Input"], Cell[TextData[{ "That's a BIG improvement. However, it is usually best to use built in ", StyleBox["Mathematica", FontSlant->"Italic"], " functions, such as Nest in this case, which are ", StyleBox["normally", FontSlant->"Italic"], " as fast or faster than user-compiled code. In this case, on my computer, \ Nest turns out to be a ", StyleBox["little", FontSlant->"Italic"], " slower, but that isn't typical." }], "Text"], Cell[BoxData[ \(Clear[fn]\)], "Input"], Cell[BoxData[ \(fn[n_, t_] := Nest[4 # \((1 - #)\) &, t, n]\)], "Input"], Cell[BoxData[ \(Timing[fn[1000000, .37]]\)], "Input"], Cell["\<\ Warning: there is no point compiling built-in functions. They are \ already compiled normally. Compile does best when there are large numbers of \ elementary operations.\ \>", "Text"] }, Closed]], Cell[CellGroupData[{ Cell[TextData[{ "Trace: Looking inside the ", StyleBox["Mathematica", FontSlant->"Italic"], " mind" }], "Section"], Cell["Here is a simple calculation, made up of several stages.", "Text"], Cell[BoxData[ \(Nest[\((4\ #\ \((1 - #)\) &)\), .2, 2]\)], "Input"], Cell["\<\ Using Trace, we can see what is happening at all these \ stages:\ \>", "Text"], Cell[BoxData[ \(Trace[Nest[\((4\ *#*\((1 - #)\) &)\), .2, 2]]\)], "Input"], Cell["\<\ Trace has a number of options which allow you to taylor its \ behaviour; see Help.\ \>", "Text"] }, Closed]], Cell[CellGroupData[{ Cell["Exercises", "ExerciseMain"], Cell["\<\ Do not look at the solution until you have completed the \ exercise!\ \>", "Text", TextAlignment->Center, FontFamily->"Helvetica", FontSize->18, FontWeight->"Bold", FontColor->RGBColor[1, 0, 0]], Cell[CellGroupData[{ Cell["Solving Recurrence Equations", "Exercise"], Cell[TextData[{ StyleBox["Mathematica", FontSlant->"Italic"], " actually has a utility for exactly solving recurrence equations (if \ possible): RSolve. Use it to find the exact solution of the equation treated \ in Compound Expressions above, and compare with the solution obtained there." }], "Text"] }, Open ]], Cell[CellGroupData[{ Cell["Solution", "Subsubsection"], Cell[BoxData[ \(Clear[y]\)], "Input"], Cell[BoxData[ \(rsoln = First[RSolve[{y[n] == a\ y[n - 1] + y[n - 2], y[0] \[Equal] 0, y[1] \[Equal] 1}, y, n]]\)], "Input"], Cell[BoxData[ \(y[10] /. rsoln // FullSimplify\)], "Input"] }, Closed]], Cell[CellGroupData[{ Cell["Tricky use of Module", "Exercise"], Cell[TextData[{ "Try evaluating ", Cell[BoxData[ \(TraditionalForm\`\[Sum]\+\(n = 0\)\%\[Infinity] 1\/\(n!!\)\)]], " exactly using Sum. [Note: n!!=n(n-2)(n-4)\[Ellipsis]", Cell[BoxData[ FormBox[GridBox[{ {\(1\ or\)}, {"2"} }], TraditionalForm]]], " is the so-called double factorial.] You should find that ", StyleBox["Mathematica", FontSlant->"Italic"], " cannot do it. However, it ", StyleBox["can", FontSlant->"Italic"], " succeed with a little bit of help from FunctionExpand; try applying it to \ 1/n!! and hence find ", Cell[BoxData[ \(TraditionalForm\`\[Sum]\+\(n = 0\)\%\[Infinity] 1\/\(n!!\)\)]], ". Check your answer numerically using NSum.\nNow, explain why ", StyleBox["this", FontSlant->"Italic"], " works (it can take a few seconds to run)" }], "Text"], Cell[BoxData[ \(\(\(\ \)\(\(gg[expr_]\)\(:=\)\(Module[{Sum, ee}, ee = MapAt[FunctionExpand, expr, 1]; ee]\)\(\ \)\)\)\)], "Input"], Cell[BoxData[ \(gg[Sum[1\/\(n!!\), {n, 0, \[Infinity]}]]\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Module or Block?", "Exercise"], Cell[TextData[{ "Assume there is a parameter, ", StyleBox["g", FontFamily->"Courier"], " say, in a function ", Cell[BoxData[ FormBox[ RowBox[{\(f(x)\), "=", RowBox[{"sin", "[", RowBox[{ StyleBox["g", FontFamily->"Courier", FontSlant->"Plain"], "/", \((x\^2 + 1)\)}], "]"}]}], TraditionalForm]]], ", but not explicitly mentioned in its arguments. Now say you want to \ create a scoping construct, i.e., a Module, Block, or With, to numerically \ calculate ", Cell[BoxData[ \(TraditionalForm\`\[Integral]\_0\%X f[x] \[DifferentialD]x\)]], ", but with ", StyleBox["g", FontFamily->"Courier"], " set to 5. How could you best do it? Why don't some obvious options work? \ Finally, define a function B(", StyleBox["g", FontFamily->"Courier"], ",X) which evaluates this integral for any given ", StyleBox["numeric", FontSlant->"Italic"], " ", StyleBox["g", FontFamily->"Courier"], "." }], "Text"] }, Open ]], Cell[CellGroupData[{ Cell["Solution", "Subsubsection"], Cell[BoxData[ \(f[x_] := \ Sin[g\/\(x\^2 + 1\)]\)], "Input"], Cell[TextData[{ StyleBox["Mathematica", FontSlant->"Italic"], " can't do the integral exactly." }], "Text"], Cell[BoxData[ \(Integrate[f[x], {x, 0, 1}]\)], "Input"], Cell["So we have to do it numerically. Does this work?", "Text"], Cell[BoxData[ \(F[X_] := Module[{g = 5}, NIntegrate[f[x], {x, 0, X}]]\)], "Input"], Cell[BoxData[ \(F[1]\)], "Input"], Cell[TextData[{ "No! NIntegrate can't work if the integrand isn't numerical; in this case \ it contains the variable ", StyleBox["g", FontFamily->"Courier"], ". Why didn't Module set ", StyleBox["g", FontFamily->"Courier"], " to 5?\nWhat about this?" }], "Text"], Cell[BoxData[ \(H[X_] := With[{g = 5}, NIntegrate[f[x], {x, 0, X}]]\)], "Input"], Cell[BoxData[ \(H[1]\)], "Input"], Cell["\<\ Again no! What is going wrong? As a last resort, let's see if Block \ works.\ \>", "Text"], Cell[BoxData[ \(G[X_] := Block[{g = 5}, NIntegrate[f[x], {x, 0, X}]]\)], "Input"], Cell[BoxData[ \(G[1]\)], "Input"], Cell["\<\ At last! Explain why Block works and Module doesn't. Now to define B. This will work:\ \>", "Text"], Cell[BoxData[ \(B[gg_, X_] := Block[{g = gg}, NIntegrate[f[x], {x, 0, X}]]\)], "Input"], Cell[BoxData[ \(B[5, 1]\)], "Input"], Cell[TextData[{ "Of course, it doesn't work if ", StyleBox["g", FontFamily->"Courier"], " is not numeric." }], "Text"], Cell[BoxData[ \(B[g, 1]\)], "Input"], Cell[TextData[{ "but it does work for any numeric ", StyleBox["g", FontFamily->"Courier"], ", even if complex." }], "Text"], Cell[BoxData[ \(B[1 + \[ImaginaryI], 1]\)], "Input"] }, Closed]], Cell[CellGroupData[{ Cell["Simple Programming Project", "Exercise"], Cell[TextData[{ "Write a Module to calculate the length of the curve in (x,y) space between \ the first two non-negative zeros of the solution of ", Cell[BoxData[ \(TraditionalForm\`\(\(y'' + \((1 + x\^4)\) y = 0\)\(,\)\)\)]], " y(0)=0, y'(0)=1. It should plot y(x) over (0,5), and return {z,len} where \ z is the first positive zero and len is the length sought." }], "Text"] }, Open ]], Cell[CellGroupData[{ Cell["Solution", "Subsubsection"], Cell[BoxData[ \(Module[{sol, z}, sol = First[ NDSolve[{\(y''\)[x] + \((1 + x\^4)\) y[x] \[Equal] 1, y[0] \[Equal] 0, \(y'\)[0] \[Equal] 1}, y, {x, 0, 5}]]; Plot[Evaluate[y[x] /. sol], {x, 0, 5}, AspectRatio \[Rule] Automatic]; \[IndentingNewLine]z = x /. FindRoot[Evaluate[y[x] /. sol], {x, 2}]; {z, NIntegrate[ Evaluate[\@\(1 + \(y'\)[x]\^2\) /. sol], {x, 0, z}]}]\)], "Input"] }, Closed]], Cell[CellGroupData[{ Cell["Advanced Programming Project", "Exercise"], Cell[TextData[{ "Extend the previous exercise by writing a module with returns the bounds \ of all the \"lobes\" (i.e., sections of curve between each successive zero of \ y) up to x=5 and their lengths in a list of the form ", Cell[BoxData[ FormBox[ RowBox[{ RowBox[{ RowBox[{ RowBox[{ RowBox[{ FormBox[\({{{z\_0, z\_1}\), "TraditionalForm"], ",", \(len\_1\)}], "}"}], ",", " ", \({{z\_1, z\_2}, \ len\_2}\), ",", " ", "\[Ellipsis]"}], "}"}], "."}], TraditionalForm]]], " It should also produce a ListPlot of lobe length against lobe number \ (1,2,3,\[Ellipsis]). You may need the utilities Select and Partition, and \ perhaps Prepend. [Hint: first make a table of y(x) for 0", "\"}]; ans\[IndentingNewLine]]\)], "Input"] }, Closed]] }, Open ]] }, FrontEndVersion->"5.2 for X", ScreenRectangle->{{0, 1280}, {0, 1024}}, AutoGeneratedPackage->Automatic, WindowSize->{699, 929}, WindowMargins->{{1, Automatic}, {Automatic, 0}}, ShowSelection->True, Magnification->1, StyleDefinitions -> "Classroom.nb" ] (******************************************************************* Cached data follows. If you edit this Notebook file directly, not using Mathematica, you must remove the line containing CacheID at the top of the file. The cache data will then be recreated when you save this file from within Mathematica. *******************************************************************) (*CellTagsOutline CellTagsIndex->{ "For"->{ Cell[8324, 315, 146, 3, 51, "Input", CellTags->"For"]}, "While"->{ Cell[9256, 352, 102, 2, 47, "Input", CellTags->"While"]}, "Compile"->{ Cell[10041, 387, 139, 4, 47, "Input", CellTags->"Compile"]} } *) (*CellTagsIndex CellTagsIndex->{ {"For", 22048, 805}, {"While", 22127, 808}, {"Compile", 22210, 811} } *) (*NotebookFileOutline Notebook[{ Cell[1754, 51, 122, 4, 70, "Title"], Cell[1879, 57, 106, 4, 41, "Subtitle"], Cell[1988, 63, 91, 3, 39, "Author"], Cell[2082, 68, 450, 9, 64, "Text"], Cell[2535, 79, 87, 2, 47, "Input", InitializationCell->True], Cell[CellGroupData[{ Cell[2647, 85, 39, 0, 64, "Section"], Cell[2689, 87, 581, 12, 112, "Text"], Cell[3273, 101, 110, 2, 47, "Input"], Cell[3386, 105, 187, 4, 46, "Text"], Cell[3576, 111, 39, 1, 47, "Input"], Cell[3618, 114, 35, 0, 28, "Text"], Cell[3656, 116, 41, 1, 47, "Input"], Cell[3700, 119, 39, 1, 47, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[3776, 125, 26, 0, 44, "Section"], Cell[3805, 127, 125, 3, 28, "Text"], Cell[3933, 132, 164, 3, 63, "Input"], Cell[4100, 137, 41, 1, 47, "Input"], Cell[4144, 140, 39, 1, 47, "Input"], Cell[4186, 143, 167, 4, 46, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[4390, 152, 25, 0, 44, "Section"], Cell[4418, 154, 294, 6, 46, "Text"], Cell[4715, 162, 163, 3, 63, "Input"], Cell[4881, 167, 41, 1, 47, "Input"], Cell[4925, 170, 39, 1, 47, "Input"], Cell[4967, 173, 95, 3, 28, "Text"], Cell[5065, 178, 43, 1, 47, "Input"], Cell[5111, 181, 54, 1, 47, "Input"], Cell[5168, 184, 55, 1, 47, "Input"], Cell[5226, 187, 128, 3, 28, "Text"], Cell[5357, 192, 47, 1, 47, "Input"], Cell[5407, 195, 177, 4, 46, "Text"], Cell[5587, 201, 47, 1, 47, "Input"], Cell[5637, 204, 175, 4, 46, "Text"], Cell[5815, 210, 46, 1, 47, "Input"], Cell[5864, 213, 32, 0, 28, "Text"], Cell[5899, 215, 92, 1, 47, "Input"], Cell[5994, 218, 41, 1, 47, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[6072, 224, 23, 0, 44, "Section"], Cell[6098, 226, 213, 4, 46, "Text"], Cell[6314, 232, 85, 1, 51, "Input"], Cell[6402, 235, 59, 0, 28, "Text"], Cell[6464, 237, 85, 1, 51, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[6586, 243, 69, 2, 44, "Section"], Cell[6658, 247, 447, 11, 64, "Text"], Cell[CellGroupData[{ Cell[7130, 262, 24, 0, 53, "Subsection"], Cell[7157, 264, 137, 3, 28, "Text"], Cell[7297, 269, 81, 1, 47, "Input"], Cell[7381, 272, 34, 0, 28, "Text"], Cell[7418, 274, 61, 1, 47, "Input"], Cell[7482, 277, 40, 0, 28, "Text"], Cell[7525, 279, 63, 1, 47, "Input"], Cell[7591, 282, 53, 0, 28, "Text"], Cell[7647, 284, 49, 1, 47, "Input"], Cell[7699, 287, 54, 0, 28, "Text"], Cell[7756, 289, 47, 1, 47, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[7840, 295, 35, 0, 37, "Subsection"], Cell[7878, 297, 443, 16, 46, "Text"], Cell[8324, 315, 146, 3, 51, "Input", CellTags->"For"], Cell[8473, 320, 62, 0, 28, "Text"], Cell[8538, 322, 38, 1, 47, "Input"], Cell[8579, 325, 674, 25, 28, "Text"], Cell[9256, 352, 102, 2, 47, "Input", CellTags->"While"], Cell[9361, 356, 39, 1, 47, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[9437, 362, 28, 0, 37, "Subsection"], Cell[9468, 364, 245, 7, 46, "Text"] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell[9762, 377, 26, 0, 44, "Section"], Cell[9791, 379, 247, 6, 28, "Text"], Cell[10041, 387, 139, 4, 47, "Input", CellTags->"Compile"], Cell[10183, 393, 91, 3, 28, "Text"], Cell[10277, 398, 50, 1, 47, "Input"], Cell[10330, 401, 224, 8, 28, "Text"], Cell[10557, 411, 135, 3, 47, "Input"], Cell[10695, 416, 411, 8, 64, "Text"], Cell[11109, 426, 58, 1, 47, "Input"], Cell[11170, 429, 448, 12, 64, "Text"], Cell[11621, 443, 42, 1, 47, "Input"], Cell[11666, 446, 77, 1, 47, "Input"], Cell[11746, 449, 58, 1, 47, "Input"], Cell[11807, 452, 193, 4, 46, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[12037, 461, 124, 5, 44, "Section"], Cell[12164, 468, 72, 0, 28, "Text"], Cell[12239, 470, 72, 1, 47, "Input"], Cell[12314, 473, 88, 3, 28, "Text"], Cell[12405, 478, 79, 1, 47, "Input"], Cell[12487, 481, 106, 3, 28, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[12630, 489, 33, 0, 46, "ExerciseMain"], Cell[12666, 491, 214, 8, 35, "Text"], Cell[CellGroupData[{ Cell[12905, 503, 48, 0, 48, "Exercise"], Cell[12956, 505, 310, 6, 46, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[13303, 516, 33, 0, 48, "Subsubsection"], Cell[13339, 518, 41, 1, 47, "Input"], Cell[13383, 521, 148, 3, 47, "Input"], Cell[13534, 526, 63, 1, 47, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[13634, 532, 40, 0, 34, "Exercise"], Cell[13677, 534, 859, 24, 111, "Text"], Cell[14539, 560, 143, 2, 47, "Input"], Cell[14685, 564, 73, 1, 64, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[14795, 570, 36, 0, 48, "Exercise"], Cell[14834, 572, 1038, 33, 83, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[15909, 610, 33, 0, 48, "Subsubsection"], Cell[15945, 612, 64, 1, 61, "Input"], Cell[16012, 615, 115, 4, 28, "Text"], Cell[16130, 621, 59, 1, 47, "Input"], Cell[16192, 624, 64, 0, 28, "Text"], Cell[16259, 626, 86, 1, 47, "Input"], Cell[16348, 629, 37, 1, 47, "Input"], Cell[16388, 632, 280, 9, 76, "Text"], Cell[16671, 643, 84, 1, 47, "Input"], Cell[16758, 646, 37, 1, 47, "Input"], Cell[16798, 649, 100, 3, 28, "Text"], Cell[16901, 654, 85, 1, 47, "Input"], Cell[16989, 657, 37, 1, 47, "Input"], Cell[17029, 660, 109, 3, 58, "Text"], Cell[17141, 665, 91, 1, 47, "Input"], Cell[17235, 668, 40, 1, 47, "Input"], Cell[17278, 671, 128, 5, 28, "Text"], Cell[17409, 678, 40, 1, 47, "Input"], Cell[17452, 681, 133, 5, 28, "Text"], Cell[17588, 688, 56, 1, 47, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[17681, 694, 46, 0, 34, "Exercise"], Cell[17730, 696, 388, 7, 64, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[18155, 708, 33, 0, 48, "Subsubsection"], Cell[18191, 710, 458, 9, 128, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[18686, 724, 48, 0, 34, "Exercise"], Cell[18737, 726, 833, 18, 82, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[19607, 749, 33, 0, 48, "Subsubsection"], Cell[19643, 751, 1697, 31, 276, "Input"] }, Closed]] }, Open ]] } ] *) (******************************************************************* End of Mathematica Notebook file. *******************************************************************)