(************** Content-type: application/mathematica ************** CreatedBy='Mathematica 5.0' 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[ 26686, 939]*) (*NotebookOutlinePosition[ 27367, 962]*) (* CellTagsIndexPosition[ 27323, 958]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell["Working with Lists, Part 1", "Title"], Cell[CellGroupData[{ Cell["Introduction", "Section"], Cell[TextData[{ "In ", StyleBox["Mathematica", FontSlant->"Italic"], ", lists are enclosed in braces. For example," }], "Text"], Cell[BoxData[ \(nsmDepartments = {"\", "\", \ "\", "\", "\", "\"}\)], \ "Input"], Cell[TextData[{ "Everything in ", StyleBox["Mathematica", FontSlant->"Italic"], ", except for individual data, is a function. So, when we use braces to \ enclose a list, ", StyleBox["Mathematica", FontSlant->"Italic"], " stores this internally as" }], "Text"], Cell[BoxData[ \(FullForm[nsmDepartments]\)], "Input"], Cell["\<\ Usually, however, we can use braces instead of List[ ] to create \ lists. We can use lists in a variety of ways \[LongDash] like arrays in \ computer programming languages, like mathematical sequences, and like vectors \ in linear algebra.\ \>", "Text"] }, Closed]], Cell[CellGroupData[{ Cell["Generating lists", "Section"], Cell[TextData[{ "You can manually type short lists, enclosed in braces, as we did with ", StyleBox["nsmDepartments", FontFamily->"Courier"], ". The most commonly used command to create lists is the ", StyleBox["Table", FontFamily->"Courier"], " command. We have used this command before to create lists of graphs. \ You can also use it to create lists of numbers. Here are the first 100 \ powers of 2." }], "Text"], Cell[BoxData[ \(Table[2\^i, {i, 100}]\)], "Input"], Cell[TextData[{ "The first argument to ", StyleBox["Table", FontFamily->"Courier"], " is an expression and the second argument is an iterator. In ", StyleBox["Mathematica", FontSlant->"Italic"], " iterators are lists of length 1, 2, 3, or 4. The meanings of the \ elements depend on the length of the list.\n{", StyleBox["imax", FontFamily->"Courier"], "} \[LongDash] ", StyleBox["Table", FontFamily->"Courier"], " iterates ", StyleBox["imax", FontFamily->"Courier"], " times without incrementing any variables.\n{", StyleBox["i", FontFamily->"Courier"], ", ", StyleBox["imax", FontFamily->"Courier"], "} \[LongDash] ", StyleBox["i", FontFamily->"Courier"], " goes from 1 to ", StyleBox["imax", FontFamily->"Courier"], " in increments of 1.\n{", StyleBox["i", FontFamily->"Courier"], ", ", StyleBox["imin", FontFamily->"Courier"], ", imax} \[LongDash] ", StyleBox["i", FontFamily->"Courier"], " goes from ", StyleBox["imin", FontFamily->"Courier"], " to ", StyleBox["imax", FontFamily->"Courier"], " in increments of 1.\n{", StyleBox["i", FontFamily->"Courier"], ", ", StyleBox["imin", FontFamily->"Courier"], ", imax, ", StyleBox["di", FontFamily->"Courier"], "} \[LongDash] ", StyleBox["i", FontFamily->"Courier"], " goes from ", StyleBox["imin", FontFamily->"Courier"], " to ", StyleBox["imax", FontFamily->"Courier"], " in increments of ", StyleBox["di", FontFamily->"Courier"], ". ", StyleBox["di", FontFamily->"Courier"], " can be a negative number." }], "Text"], Cell[TextData[{ "Here are the ", Cell[BoxData[ \(TraditionalForm\`100\^th\)]], " through ", Cell[BoxData[ \(TraditionalForm\`125\^th\)]], " powers of 1 + ", Cell[BoxData[ \(TraditionalForm\`\@3\)]], "." }], "Text"], Cell[BoxData[ \(Table[Expand[\((1 + \@3)\)\^n], {n, 100, 125}]\)], "Input"], Cell["And here are the squares of the half integers from 10 to 20.", "Text"], Cell[BoxData[ \(Table[n\^2, {n, 10, 20, 1\/2}]\)], "Input"], Cell["\<\ We have already seen how to create a list of graphs, which can be \ used to show an animation. For example,\ \>", "Text"], Cell[BoxData[ \(\(Table[ Plot3D[Sin[\(x\^2 + y\^2\)\/a], {x, \(-2\) \[Pi], 2 \[Pi]}, {y, \(-2\) \[Pi], 2 \[Pi]}, PlotRange \[Rule] {\(-1\), 1}], {a, 4, 12}];\)\)], "Input"], Cell[TextData[{ "If you want to display the graphs of a set of functions all in one plot, \ you have to create the list of graphs first, turning off the display, and \ then use ", StyleBox["Show", FontFamily->"Courier"], " to display them together in one plot." }], "Text"], Cell[BoxData[{ \(\(exponentialPlots = Table[Plot[\[ExponentialE]\^\(a\ t\), {t, \(-3\), 3}, PlotRange \[Rule] {0, 5}, DisplayFunction \[Rule] Identity], {a, \(-4\), 4}];\)\), "\[IndentingNewLine]", \(\(Show[exponentialPlots, DisplayFunction \[Rule] $DisplayFunction];\)\)}], "Input"], Cell[TextData[{ "Notice that it is difficult to see which curve represents which function. \ You can fix this by using the value of ", StyleBox["a", FontSlant->"Italic"], " to determine the color of the curve. The color is specified with ", StyleBox["RGBColor", FontFamily->"Courier"], "[", StyleBox["r", FontSlant->"Italic"], ", ", StyleBox["g", FontSlant->"Italic"], ", ", StyleBox["b", FontSlant->"Italic"], "], where the values of the three arguments to ", StyleBox["RGBColor", FontFamily->"Courier"], " range from 0 to 1 and determine the amount of red, green, and blue, \ respectively. If we want the colors of our graphs to vary from red to green, \ then we want ", StyleBox["RGBColor", FontFamily->"Courier"], " to vary from ", StyleBox["RGBColor", FontFamily->"Courier"], "[1, 0 , 0] to ", StyleBox["RGBColor", FontFamily->"Courier"], "[0, 1, 0]. So, we need two functions, say red[a] and green[a]. The red \ function needs to go from 1 to 0 as ", StyleBox["a", FontSlant->"Italic"], " goes from \[Dash]4 to 4. The green function needs to go from 0 to 1 as \ ", StyleBox["a", FontSlant->"Italic"], " goes from \[Dash]4 to 4. The simplest functions that we can use are \ linear. Using the point-slope form for the equation of a line," }], "Text"], Cell[BoxData[{ \(Clear[red]\), "\[IndentingNewLine]", \(red[a_] = \(\(0 - 1\)\/\(4 - \((\(-4\))\)\)\) \((a - \((\(-4\))\))\) + 1\)}], "Input"], Cell[BoxData[{ \(Clear[green]\), "\[IndentingNewLine]", \(green[ a_] = \(\(1 - 0\)\/\(4 - \((\(-4\))\)\)\) \((a - \((\(-4\))\))\) + 0\)}], "Input"], Cell["Let's check these functions out with a plot.", "Text"], Cell[BoxData[ \(\(Plot[{red[a], green[a]}, {a, \(-4\), 4}];\)\)], "Input"], Cell[TextData[{ "Just what we wanted. Now let's insert these into ", StyleBox["RGBColor", FontFamily->"Courier"], " within the ", StyleBox["PlotStyle", FontFamily->"Courier"], " option." }], "Text"], Cell[BoxData[{ \(\(exponentialPlots = Table[Plot[\[ExponentialE]\^\(a\ t\), {t, \(-3\), 3}, PlotRange \[Rule] {0, 5}, PlotStyle \[Rule] {{RGBColor[red[a], green[a], 0]}}, DisplayFunction \[Rule] Identity], {a, \(-4\), 4}];\)\), "\[IndentingNewLine]", \(\(Show[exponentialPlots, DisplayFunction \[Rule] $DisplayFunction];\)\)}], "Input"], Cell[TextData[{ StyleBox["Exercise 9.1:", FontWeight->"Bold", FontColor->RGBColor[0, 0.500008, 0.250004]], " Display on one graph the functions Sin[x], 0.9 Sin[x/0.9], 0.8 \ Sin[x/0.8], ..., 0.1 Sin[x/0.1] for \[Dash]2\[Pi] < ", StyleBox["x", FontSlant->"Italic"], " < 2\[Pi]. Make the colors of the curves range from red to blue." }], "Text", Background->GrayLevel[0.750011]], Cell[TextData[{ "You can also use ", StyleBox["Table", FontFamily->"Courier"], " to create lists within lists. The first iterator (", StyleBox["i", FontFamily->"Courier"], " in the example below) is the outermost list. Here is a multiplication \ table." }], "Text"], Cell[BoxData[ \(Table[i*j, {i, 12}, {j, 10}]\)], "Input"], Cell[TextData[{ "Or you can see the values displayed in rows and columns (each inner list \ is a row), using ", StyleBox["TableForm", FontFamily->"Courier"], "." }], "Text"], Cell[BoxData[ \(TableForm[Table[i*j, {i, 12}, {j, 10}]]\)], "Input"], Cell[TextData[{ StyleBox["Mathematica", FontSlant->"Italic"], " has an alternative syntax for functions with only one argument. This \ alternative syntax is often used with ", StyleBox["TableForm", FontFamily->"Courier"], " to de-emphasize it. ", StyleBox["Table", FontFamily->"Courier"], " is the most important function in the command above, not ", StyleBox["TableForm", FontFamily->"Courier"], ". The following syntax reflects that emphasis." }], "Text"], Cell[BoxData[ \(Table[i*j, {i, 12}, {j, 10}] // TableForm\)], "Input"], Cell["Here is Pascal's triangle.", "Text"], Cell[BoxData[ \(Table[Binomial[i, j], {i, 0, 8}, {j, 0, i}] // TableForm\)], "Input"], Cell[TextData[{ " The entries in Pascal's triangle are called binomial coefficients because \ they are the coefficients in the expanded form of the binomial ", Cell[BoxData[ \(TraditionalForm\`\((x + y)\)\^n\)]], "." }], "Text"], Cell[BoxData[{ \(Clear[x, y]\), "\[IndentingNewLine]", \(Table[Expand[\((x + y)\)\^n], {n, 0, 8}] // TableForm\)}], "Input"], Cell[TextData[{ StyleBox["Range", FontFamily->"Courier"], " creates sequences of numbers with uniform increments. It uses the same \ iteration specification as ", StyleBox["Table", FontFamily->"Courier"], ". Here are some examples." }], "Text"], Cell[BoxData[ \(Range[10]\)], "Input"], Cell[BoxData[ \(Range[5, 10]\)], "Input"], Cell[BoxData[ \(Range[0, 4 \[Pi], \[Pi]\/3]\)], "Input"], Cell[TextData[{ "Another method for creating lists is by reading data from a file, using ", StyleBox["ReadList", FontFamily->"Courier"], ", ", StyleBox["Read", FontFamily->"Courier"], ", or ", StyleBox["Import", FontFamily->"Courier"], ". In this example we read a list of country names and their populations \ in 2006, with one country per line. Each line starts with the country name, \ followed by a tab character and then the population. This is called a \ tab-delimited text file. The second argument to ", StyleBox["Import", FontFamily->"Courier"], " is the file format. ", StyleBox["TSV", FontFamily->"Courier"], " stands for tab-separated values. You will have to download the ", ButtonBox["worldpopulation2006.txt", ButtonData:>{ URL[ "http://www.math.iup.edu/~hedonley/math281/worldpopulation2006.txt"], None}, ButtonStyle->"Hyperlink"], " data file, and change the path name in the following command to match the \ directory to which you have downloaded the file. You need to use double \ backslashes instead of the single backslashes that you usually use in Windows \ directory path names." }], "Text"], Cell[BoxData[ \(population = Import["\", \ "\"]\)], "Input"], Cell[TextData[{ "Source: U.S. Census Bureau, ", ButtonBox["http://www.census.gov/ipc/www/idbrank.html", ButtonData:>{ URL[ "http://www.census.gov/ipc/www/idbrank.html"], None}, ButtonStyle->"Hyperlink"], "." }], "Text"] }, Closed]], Cell[CellGroupData[{ Cell["Lists as arrays", "Section"], Cell[TextData[{ "There are several paradigms for ", StyleBox["Mathematica", FontSlant->"Italic"], "'s lists. For instance, we can think of them as arrays, sequences, or \ vectors. In this section, we will study the list operations that treat lists \ like arrays in traditional computer programming languages, such as C++ or \ Java." }], "Text"], Cell[TextData[{ "If you haven't already done so, load the world population data using the \ above command. This creates an array named ", StyleBox["population", FontFamily->"Courier"], ". Each entry in the list is another list of two elements. The first \ element is the country name and the second element is the country population. \ The countries are sorted from most populous to least populous. You can \ extract individual elements or groups of elements using the ", StyleBox["Part", FontFamily->"Courier"], " command. The second most populous country is" }], "Text"], Cell[BoxData[ \(Part[population, 2]\)], "Input"], Cell["You can also write this in the form", "Text"], Cell[BoxData[ \(population[\([2]\)]\)], "Input"], Cell["or, using the Basic Input palette,", "Text"], Cell[BoxData[ \(population\_\(\(\[LeftDoubleBracket]\)\(2\)\(\[RightDoubleBracket]\)\)\)\ ], "Input"], Cell[TextData[{ "The name of the ", Cell[BoxData[ \(TraditionalForm\`5\^th\)]], "most populous country is" }], "Text"], Cell[BoxData[ \(population[\([5, 1]\)]\)], "Input"], Cell["and its population is", "Text"], Cell[BoxData[ \(population[\([5, 2]\)]\)], "Input"], Cell["or equivalently", "Text"], Cell[BoxData[ \(\(population[\([5]\)]\)[\([2]\)]\)], "Input"], Cell[TextData[{ "Negative arguments in ", StyleBox["Part", FontFamily->"Courier"], " count from the end of the list. For example, the second to the least \ populated country is:" }], "Text"], Cell[BoxData[ \(population[\([\(-2\)]\)]\)], "Input"], Cell[TextData[{ "The arguments to ", StyleBox["Part", FontFamily->"Courier"], " can be lists, allowing you to extract sublists. Here are the ten most \ populous countries." }], "Text"], Cell[BoxData[ \(population[\([{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}]\)]\)], "Input"], Cell["\<\ How could you use one of the commands from the previous section in \ the above command to list the 10 most populous countries, instead of typing \ all of the integers from 1 to 10?\ \>", "Text"], Cell["\<\ Look up First, Last, Take, Drop, Rest, Reverse, and Length in the \ Help Browser.\ \>", "Text"], Cell[TextData[{ StyleBox["Exercise 9.2:", FontWeight->"Bold", FontColor->RGBColor[0, 0.500008, 0.250004]], " How many countries are there in the world, according to the United \ Nations? Find three different ways to use ", StyleBox["Mathematica", FontSlant->"Italic"], " commands to list the 10 least populous countries." }], "Text", Background->GrayLevel[0.750011]], Cell["\<\ You can add elements to your list using Append, Prepend, or Insert.\ \ \>", "Text"], Cell["\<\ Suppose that you lived in Key West, Florida, and wanted to secede \ from United States to form the Conch Republic. According to the 2000 U.S. \ census, the population of Key West is 25478. We can append this to our \ population list and then sort the \ \>", "Text"], Cell[BoxData[ \(population = Append[population, \ {"\", 25478}]\)], "Input"], Cell[TextData[{ "But notice that this placed Key West at the end of our list and now our \ population data are no longer in descending order. We really need to insert \ it between the ", Cell[BoxData[ \(TraditionalForm\`216\^th\)]], " country and the ", Cell[BoxData[ \(TraditionalForm\`217\^th\)]], " country." }], "Text"], Cell[BoxData[ \(population[\([{216, 217}]\)]\)], "Input"], Cell[TextData[{ "So, let's delete Key West from the end of our list and insert it as the ", Cell[BoxData[ \(TraditionalForm\`217\^th\)]], " country." }], "Text"], Cell[BoxData[ \(population = Drop[population, \(-1\)]\)], "Input"], Cell[BoxData[ \(population = Insert[population, {"\", 25478}, 217]\)], "Input"], Cell["\<\ You also need to decrease the U.S. population by the population of \ Key West. See if you can do this.\ \>", "Text"], Cell[TextData[{ "Other commands for removing or replacing elements are ", StyleBox["Take", FontFamily->"Courier"], ", ", StyleBox["Delete", FontFamily->"Courier"], ", and ", StyleBox["ReplacePart", FontFamily->"Courier"], "." }], "Text"] }, Closed]], Cell[CellGroupData[{ Cell["Lists as sequences", "Section"], Cell["Sequences can be represented as lists. ", "Text"], Cell["Here is a simple arithmetic sequence.", "Text"], Cell[BoxData[ \(3\ Range[20] + 2\)], "Input"], Cell["and here is a geometric sequence", "Text"], Cell[BoxData[ \(Table[2\ \((1\/3)\)\^n, {n, 0, 20}]\)], "Input"], Cell[TextData[{ "Many mathematical functions in ", StyleBox["Mathematica", FontSlant->"Italic"], " are ", StyleBox["Listable", FontFamily->"Courier"], ", meaning that you can give a list of ", StyleBox["x", FontSlant->"Italic"], " values as an argument and ", StyleBox["Mathematica", FontSlant->"Italic"], " will generate a list of ", StyleBox["y", FontSlant->"Italic"], " values. Here is a sequence of values of the ", StyleBox["Sin", FontFamily->"Courier"], " function." }], "Text"], Cell[BoxData[ \(Sin[Range[0. , 3 \[Pi], \[Pi]\/12. ]]\)], "Input"], Cell[TextData[{ "Some sequences are defined recursively; that is, the elements of the \ sequence are calculated from the values of previous elements in the sequence. \ One example is the Fibonacci sequence\n\n", Cell[BoxData[{ \(TraditionalForm\`a\_1 = 1\), "\[IndentingNewLine]", \(TraditionalForm\`a\_2 = 1\), "\[IndentingNewLine]", \(TraditionalForm\`a\_n = a\_\(n - 1\) + a\_\(n - 2\), \ n = 3, 4, \ 5, \ ... \)}]] }], "Text"], Cell[TextData[{ "We will define a function, ", StyleBox["fibonacci", FontSlant->"Italic"], ", as a function of ", StyleBox["n", FontSlant->"Italic"], "." }], "Text"], Cell[BoxData[{ \(Clear[fibonacci]\), "\[IndentingNewLine]", \(\(fibonacci[1] = 1;\)\), "\[IndentingNewLine]", \(\(fibonacci[2] = 1;\)\), "\[IndentingNewLine]", \(fibonacci[n_] := fibonacci[n - 1] + fibonacci[n - 2]\)}], "Input"], Cell["\<\ There are three features of this definition that warrant further \ explanation. \ \>", "Text"], Cell[TextData[{ "1) Notice that there is no underscore after the 1 and 2 in the first two \ lines. We define fibonacci[1] and fibonacci[2] instead of fibonacci[1_] and \ fibonacci[2_]. This is because 1 and 2 are specific values. In contrast, \ the ", StyleBox["n", FontSlant->"Italic"], " in the third line is followed by an underscore. This is because ", StyleBox["n", FontSlant->"Italic"], " is a", " variable to be replaced by some specific value at the time that the \ function is to be evaluated. " }], "Text"], Cell[TextData[{ "2) The first two lines use an equal sign for the assignment and the third \ line uses ", StyleBox[":=", FontFamily->"Courier"], ". The equal sign means to evaluate the right side immediately and assign \ that value to the function. The ", StyleBox[":=", FontFamily->"Courier"], " means to delay evaluation of the right side until the function is \ actually used to find the value of fibonacci at some particular ", StyleBox["n", FontSlant->"Italic"], ". You can more clearly see the distinction between these two types of \ assignments in the following example." }], "Text"], Cell[TextData[{ "In this version of ", StyleBox["f", FontSlant->"Italic"], ", the right hand side is evaluated immediately, using the current value of \ ", StyleBox["a", FontSlant->"Italic"], "." }], "Text"], Cell[BoxData[{ \(Clear[f, a]\), "\[IndentingNewLine]", \(\(a = 4;\)\), "\[IndentingNewLine]", \(f[x_] = x\^2 - a\)}], "Input"], Cell["The value of f[3]is no surprise.", "Text"], Cell[BoxData[ \(f[3]\)], "Input"], Cell[TextData[{ "If we change the value of ", StyleBox["a", FontSlant->"Italic"], ", this will not effect the definition of ", StyleBox["f", FontSlant->"Italic"], "." }], "Text"], Cell[BoxData[{ \(\(a = 100;\)\), "\[IndentingNewLine]", \(f[3]\)}], "Input"], Cell[TextData[{ "Now, suppose that we delay the evaluation of the right hand side, using \ the ", StyleBox[":=", FontFamily->"Courier"], " assignment." }], "Text"], Cell[BoxData[{ \(Clear[f, a]\), "\[IndentingNewLine]", \(\(a = 4;\)\), "\[IndentingNewLine]", \(f[x_] := x\^2 - a\)}], "Input"], Cell["Again, the value of f[3]is no surprise.", "Text"], Cell[BoxData[ \(f[3]\)], "Input"], Cell[TextData[{ "Now look what happens when we change the value of ", StyleBox["a", FontSlant->"Italic"], ". Since the right side of the equation is not evaluated until we use it, \ the new value of ", StyleBox["a", FontSlant->"Italic"], " is used." }], "Text"], Cell[BoxData[{ \(\(a = 100;\)\), "\[IndentingNewLine]", \(f[3]\)}], "Input"], Cell[TextData[{ "We delay the evaluation of the Fibonacci sequence definition, because we \ need to know what ", StyleBox["n", FontSlant->"Italic"], " is before we can determine how far to go out in the sequence." }], "Text"], Cell[TextData[{ "3) If we want to calculate the ", Cell[BoxData[ \(TraditionalForm\`100\^th\)]], " Fibonacci number, we will need to calculate all of the 99 previous \ Fibonacci numbers first. This will become quite computationally intensive \ for large values of ", StyleBox["n", FontSlant->"Italic"], ". Later, we will see a slick trick for calculating the ", Cell[BoxData[ \(TraditionalForm\`n\^th\)]], " Fibonacci number directly." }], "Text"], Cell[TextData[{ "Here is the ", Cell[BoxData[ \(TraditionalForm\`25\^th\)]], " Fibonacci number." }], "Text"], Cell[BoxData[ \(fibonacci[25]\)], "Input"], Cell["\<\ Here is a sneaky trick for saving the Fibonacci numbers the first \ time that we calculate them. The next time that we need a Fibonacci number \ that we had previously calculated, we only need to look it up instead of \ calculating it again, similar to what we do for the first and second \ Fibonacci number.\ \>", "Text"], Cell[BoxData[{ \(Clear[fibonacci]\), "\[IndentingNewLine]", \(\(fibonacci[1] = 1;\)\), "\[IndentingNewLine]", \(\(fibonacci[2] = 1;\)\), "\[IndentingNewLine]", \(fibonacci[n_] := \(fibonacci[n] = fibonacci[n - 1] + fibonacci[n - 2]\)\)}], "Input"], Cell[TextData[{ "Here are the first 100 Fibonacci numbers. Notice how quickly ", StyleBox["Mathematica", FontSlant->"Italic"], " calculates these. Don't try this with the previous definition of \ fibonacci, unless you want to wait a long time for the results!" }], "Text"], Cell[BoxData[ \(Table[fibonacci[n], {n, 100}]\)], "Input"], Cell[TextData[{ StyleBox["Exercise 9.3:", FontWeight->"Bold", FontColor->RGBColor[0, 0.500008, 0.250004]], " Construct a sequence of the ratios of consecutive terms of the Fibonacci \ sequence, ", Cell[BoxData[ \(TraditionalForm\`a\_\(n + 1\)\/a\_n\)]], ". Give decimal approximations to the first 50 terms to 20 decimal places. \ Does it look like the ratios are approaching some value?" }], "Text", Background->GrayLevel[0.750011]], Cell[TextData[{ "You can use ", StyleBox["Nest", FontFamily->"Courier"], ", ", StyleBox["NestList", FontFamily->"Courier"], ", ", StyleBox["NestWhile", FontFamily->"Courier"], ", and ", StyleBox["FixedPoint", FontFamily->"Courier"], " to construct sequences of compositions of functions with itself. For \ example, this is how ", StyleBox["NestList", FontFamily->"Courier"], " works." }], "Text"], Cell[BoxData[{ \(Clear[f, x]\), "\[IndentingNewLine]", \(NestList[f, x, 6]\)}], "Input"], Cell[TextData[{ "Continued fractions are a mathematical appliction of ", StyleBox["NestList", FontFamily->"Courier"], ". Here is an example of a continued fraction." }], "Text"], Cell[BoxData[{ \(Clear[f]\), "\n", \(\(f[x_] = 1\/\(1 + x\);\)\), "\n", \(NestList[f, x, 5]\)}], "Input"], Cell["\<\ Here are the first 100 terms in the sequence if we start with 3.0. \ Note: I started with a decimal value, so that all my calculations would use \ decimal arithmetic instead of giving exact rational number results.\ \>", \ "Text"], Cell[BoxData[ \(NestList[f, 3.0, 100]\)], "Input"], Cell["Does this sequence appear to converge? ", "Text"], Cell[TextData[{ StyleBox["Exercise 9.4:", FontWeight->"Bold", FontColor->RGBColor[0, 0.500008, 0.250004]], " Find the exact value for the limit of this sequence. Hint: The \ recursive definition of this sequence is ", Cell[BoxData[ \(TraditionalForm\`a\_n = 1\/\(1\ + \ a\_\(n - 1\)\)\)]], ". Suppose that ", Cell[BoxData[ \(TraditionalForm\`lim\+\(n \[Rule] \[Infinity]\)a\_n = L\)]], ". Take the limit as ", StyleBox["n", FontSlant->"Italic"], " \[Rule]\[Infinity]", " of both sides of the recursive equation to find an equation that ", StyleBox["L", FontSlant->"Italic"], " must satisfy." }], "Text", Background->GrayLevel[0.750011]] }, Closed]] }, Open ]] }, FrontEndVersion->"5.0 for Microsoft Windows", ScreenRectangle->{{0, 1024}, {0, 695}}, WindowSize->{941, 668}, WindowMargins->{{0, Automatic}, {Automatic, 0}}, StyleDefinitions -> "PastelColor.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->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[1776, 53, 43, 0, 98, "Title"], Cell[CellGroupData[{ Cell[1844, 57, 31, 0, 51, "Section"], Cell[1878, 59, 138, 5, 29, "Text"], Cell[2019, 66, 163, 3, 38, "Input"], Cell[2185, 71, 278, 9, 29, "Text"], Cell[2466, 82, 57, 1, 38, "Input"], Cell[2526, 85, 264, 5, 50, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[2827, 95, 35, 0, 35, "Section"], Cell[2865, 97, 436, 10, 50, "Text"], Cell[3304, 109, 54, 1, 39, "Input"], Cell[3361, 112, 1649, 69, 134, "Text"], Cell[5013, 183, 246, 11, 29, "Text"], Cell[5262, 196, 79, 1, 41, "Input"], Cell[5344, 199, 76, 0, 29, "Text"], Cell[5423, 201, 63, 1, 50, "Input"], Cell[5489, 204, 132, 3, 29, "Text"], Cell[5624, 209, 210, 4, 53, "Input"], Cell[5837, 215, 283, 7, 50, "Text"], Cell[6123, 224, 349, 7, 58, "Input"], Cell[6475, 233, 1352, 41, 113, "Text"], Cell[7830, 276, 160, 3, 73, "Input"], Cell[7993, 281, 173, 4, 73, "Input"], Cell[8169, 287, 60, 0, 29, "Text"], Cell[8232, 289, 78, 1, 38, "Input"], Cell[8313, 292, 217, 8, 29, "Text"], Cell[8533, 302, 415, 8, 98, "Input"], Cell[8951, 312, 400, 10, 56, "Text"], Cell[9354, 324, 285, 9, 29, "Text"], Cell[9642, 335, 61, 1, 38, "Input"], Cell[9706, 338, 183, 6, 29, "Text"], Cell[9892, 346, 72, 1, 38, "Input"], Cell[9967, 349, 492, 14, 50, "Text"], Cell[10462, 365, 74, 1, 38, "Input"], Cell[10539, 368, 42, 0, 29, "Text"], Cell[10584, 370, 89, 1, 38, "Input"], Cell[10676, 373, 240, 6, 29, "Text"], Cell[10919, 381, 133, 2, 58, "Input"], Cell[11055, 385, 262, 8, 29, "Text"], Cell[11320, 395, 42, 1, 38, "Input"], Cell[11365, 398, 45, 1, 38, "Input"], Cell[11413, 401, 61, 1, 48, "Input"], Cell[11477, 404, 1195, 30, 113, "Text"], Cell[12675, 436, 187, 4, 78, "Input"], Cell[12865, 442, 239, 7, 29, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[13141, 454, 34, 0, 35, "Section"], Cell[13178, 456, 356, 8, 50, "Text"], Cell[13537, 466, 597, 12, 71, "Text"], Cell[14137, 480, 52, 1, 38, "Input"], Cell[14192, 483, 51, 0, 29, "Text"], Cell[14246, 485, 52, 1, 38, "Input"], Cell[14301, 488, 50, 0, 29, "Text"], Cell[14354, 490, 105, 2, 39, "Input"], Cell[14462, 494, 130, 5, 29, "Text"], Cell[14595, 501, 55, 1, 38, "Input"], Cell[14653, 504, 37, 0, 29, "Text"], Cell[14693, 506, 55, 1, 38, "Input"], Cell[14751, 509, 31, 0, 29, "Text"], Cell[14785, 511, 65, 1, 38, "Input"], Cell[14853, 514, 201, 6, 29, "Text"], Cell[15057, 522, 57, 1, 38, "Input"], Cell[15117, 525, 195, 6, 29, "Text"], Cell[15315, 533, 82, 1, 38, "Input"], Cell[15400, 536, 204, 4, 50, "Text"], Cell[15607, 542, 105, 3, 29, "Text"], Cell[15715, 547, 389, 10, 56, "Text"], Cell[16107, 559, 93, 3, 29, "Text"], Cell[16203, 564, 277, 5, 50, "Text"], Cell[16483, 571, 91, 1, 38, "Input"], Cell[16577, 574, 346, 10, 50, "Text"], Cell[16926, 586, 61, 1, 38, "Input"], Cell[16990, 589, 173, 5, 29, "Text"], Cell[17166, 596, 70, 1, 38, "Input"], Cell[17239, 599, 101, 2, 38, "Input"], Cell[17343, 603, 127, 3, 29, "Text"], Cell[17473, 608, 263, 11, 29, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[17773, 624, 37, 0, 35, "Section"], Cell[17813, 626, 56, 0, 29, "Text"], Cell[17872, 628, 53, 0, 29, "Text"], Cell[17928, 630, 49, 1, 38, "Input"], Cell[17980, 633, 48, 0, 29, "Text"], Cell[18031, 635, 68, 1, 50, "Input"], Cell[18102, 638, 535, 20, 50, "Text"], Cell[18640, 660, 71, 1, 48, "Input"], Cell[18714, 663, 463, 9, 124, "Text"], Cell[19180, 674, 183, 8, 29, "Text"], Cell[19366, 684, 247, 4, 98, "Input"], Cell[19616, 690, 105, 3, 29, "Text"], Cell[19724, 695, 541, 13, 71, "Text"], Cell[20268, 710, 620, 15, 71, "Text"], Cell[20891, 727, 225, 9, 29, "Text"], Cell[21119, 738, 140, 3, 78, "Input"], Cell[21262, 743, 48, 0, 29, "Text"], Cell[21313, 745, 37, 1, 38, "Input"], Cell[21353, 748, 196, 8, 29, "Text"], Cell[21552, 758, 85, 2, 58, "Input"], Cell[21640, 762, 173, 6, 29, "Text"], Cell[21816, 770, 141, 3, 78, "Input"], Cell[21960, 775, 55, 0, 29, "Text"], Cell[22018, 777, 37, 1, 38, "Input"], Cell[22058, 780, 280, 9, 29, "Text"], Cell[22341, 791, 85, 2, 58, "Input"], Cell[22429, 795, 235, 6, 29, "Text"], Cell[22667, 803, 479, 13, 50, "Text"], Cell[23149, 818, 121, 5, 29, "Text"], Cell[23273, 825, 46, 1, 38, "Input"], Cell[23322, 828, 333, 6, 50, "Text"], Cell[23658, 836, 275, 5, 98, "Input"], Cell[23936, 843, 284, 6, 50, "Text"], Cell[24223, 851, 62, 1, 38, "Input"], Cell[24288, 854, 459, 11, 61, "Text"], Cell[24750, 867, 439, 18, 29, "Text"], Cell[25192, 887, 97, 2, 58, "Input"], Cell[25292, 891, 188, 5, 29, "Text"], Cell[25483, 898, 119, 3, 92, "Input"], Cell[25605, 903, 241, 5, 50, "Text"], Cell[25849, 910, 54, 1, 38, "Input"], Cell[25906, 913, 56, 0, 29, "Text"], Cell[25965, 915, 693, 20, 61, "Text"] }, Closed]] }, Open ]] } ] *) (******************************************************************* End of Mathematica Notebook file. *******************************************************************)