Introduction to Lists and Tables

Keywords

Dynamical systems; Engineering applications; Lists; Graphing lists

4.1 Lists and List Operations

4.1.1 Defining Lists

A list of n elements is a Mathematica object of the form

list={a1,a2,a3,...,an}.

The ith element of the list is extracted from list with list[[i]] or Part[list,i].

Elements of a list are separated by commas. Lists are always enclosed in braces {...} and each element of a list may be (almost any) Mathematica object, even other lists. Because lists are Mathematica objects, they can be named. For easy reference, we will usually name lists.

Lists can be defined in a variety of ways: they may be completely typed in, imported from other programs and text files, or they may be created with either the Table or Array commands. Given a function f(x)Image and a number n, the command

1.  Table[f[i],{i,n}] creates the list {f[1],...,f[n]};

2.  Table[f[i],{i,0,n}] creates the list {f[0],...,f[n]};

3. Table[f[i],{i,n,m}] creates the list

{f[n],f[n+1],...,f[m-1],f[m]};

4. Table[f[i],{i,imin,imax,istep}] creates the list

{f[imin],f[imin+istep],f[imin+2*istep],...,f[imax]};

and

5.  Array[f,n] creates the list {f[1],...,f[n]}.

Table and Manipulate have nearly identical syntax. With Manipulate, you can create an interactive dynamic application; Table returns non-adjustable results.

In particular,

Table[f[x],{x,a,b,(b-a)/(n-1)}]

returns a list of f(x)Image values for n equally spaced values of x between a and b;

Table[{x,f[x]},{x,a,b,(b-a)/(n-1)}]

returns a list of points (x,f(x))Image for n equally spaced values of x between a and b.

Image

In addition to using Table, lists of numbers can be calculated using Range.

1.  Range[n] generates the list {1,2, ... , n};

2.  Range[n1,n2] generates the list {n1, n1+1, ... , n2-1, n2}; and

3. Range[n1,n2,nstep] generates the list

{n1, n1+nstep,n1+2*nstep, ... , n2-nstep,n2}.

Example 4.1

Use Mathematica to generate the list {1,2,3,4,5,6,7,8,9,10}.

Solution

Generally, a given list can be constructed in several ways. In fact, each of the following five commands generates the list {1,2,3,4,5,6,7,8,9,10}.

{ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } Image

{ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } Image

Table [ i , { i , 10 } ] Image

{ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } Image

Table [ i , { i , 1 , 10 } ] Image

{1,2,3,4,5,6,7,8,9,10}Image

Table [ i 2 , { i , 2 , 20 , 2 } ] Image

{ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } Image

Range [ 10 ] Image

{1,2,3,4,5,6,7,8,9,10}Image □

Example 4.2

Use Mathematica to define listone to be the list of numbers {1,3/2,2,5/2,3,7/2,4}Image.

Solution

In this case, we generate a list and name the result listone. As in Example 4.1, we illustrate that listone can be created in several ways.

listone = { 1 , 3 2 , 2 , 5 2 , 3 , 7 2 , 4 } Image

{ 1 , 3 2 , 2 , 5 2 , 3 , 7 2 , 4 } Image

listone = Table [ i , { i , 1 , 4 , 1 2 } ] Image

{ 1 , 3 2 , 2 , 5 2 , 3 , 7 2 , 4 } Image

Last, we define i(n)=12n+12Image and use Array to create the table listone.

i [ n _ ] = n 2 + 1 2 ; Image

listone = Array [ i , 7 ] Image

{1,32,2,52,3,72,4}Image  □

Example 4.3

Create a list of the first 25 prime numbers. What is the fifteenth prime number?

Solution

The command Prime[n] yields the nth prime number. We use Table to generate a list of the ordered pairs {n,Prime[n]} for n=1Image, 2, 3, …, 25 and name the resulting list list. We then use verb+Short+ to obtain an abbreviated portion of list. Generally, Short returns the first and last few elements of a list. The number of omitted terms between the first few and last few is indicated with <<n>>. In this case, we see that 13 terms are omitted.

list = Table [ { n , Prime [ n ] } , { n , 1 , 25 } ] ; Image

Short [ list ] Image

{{1,2},{2,3},{3,5},{4,7},{5,11},{6,13},13,{20,71},{21,73},{22,79},{23,83},{24,89},{25,97}}Image

The ith element of a list list is extracted from list with list[[i]] or Part[list,i]. From the resulting output, we see that the fifteenth prime number is 47.

list [ [ 15 ] ] Image

{ 15 , 47 } Image

Part [ list , 15 ] Image

{15,47}Image  □

Remark 4.1

You can use the Manipulate function in nearly the exact same way as the Table function. With Manipulate, the result is an interactive dynamic object that can be saved as an application that can be run outside of Mathematica.

In addition, we can use Table to generate lists consisting of the same or similar objects.

Example 4.4

(a) Generate a list consisting of five copies of the letter a. (b) Generate a list consisting of ten random integers between −10 and 10 and then a list of ten random real numbers between −10 and 10.

Solution

Entering

Clear [ a ] Image

Table [ a , { 5 } ] Image

{ a , a , a , a , a } Image

generates a list consisting of five copies of the letter a. For (b), we use the command RandomInteger and RandomReal to generate the desired lists. Because we are using RandomInteger and RandomReal, your results will certainly differ from those obtained here.

RandomInteger [ { 10 , 10 } , 10 ] Image

{ 3 , 7 , 9 , 5 , 4 , 10 , 7 , 8 , 7 , 8 } Image

RandomReal [ { 10 , 10 } , 10 ] Image

{4.71284,1.69439,6.60498,8.12249,5.20831,6.73414,1.84369,9.16472,8.96906,6.04237}Image □

Manipulate works in much the same way as Table but allows you to interactively see how adjusting parameters affects a given situation.

Example 4.5

For example, in polar coordinates, the graphs of r=sinnθImage and r=cosnθImage are n-leaved roses if n is odd and 2n-leaved roses if n is even. If n is even, the area of the graph enclosed by the 2n roses is A=1202πr2dθ=π/2Image. While if n is odd, the area of the graph enclosed by the n roses is A=1202πr2dθ=π/4Image.

To see this with Mathematica, we can use Table. (See Figs. 4.1 and 4.2.) (Note that If[condition,f,g] returns f if condition is True and g if it is not.)

Image
Figure 4.1 You can use Table to see that the area of the roses depends only on whether n is odd or even. (University of Colorado-Boulder colors)
Image
Figure 4.2 With Manipulate you can see that the area alternates from π/2 to π/4 as n alternates from even to odd.

Clear [ n , x ] ; Image

t1 = Table [ { Image

If [ Mod [ n / 2 , 1 ] === 0 , Integrate [ Sin [ n x ] 2 , { x , 0 , 2 Pi } ] / 2 , Image

Integrate [ Sin [ n x ] 2 , { x , 0 , Pi } ] / 2 ] , Image

PolarPlot[Sin[nx],{x,0,2Pi},Image

PlotRange { { 3 / 2 , 3 / 2 } , { 3 / 2 , 3 / 2 } } , AspectRatio 1 , Image

PlotStyle { { CMYKColor [ 0 , . 1 , . 48 , . 22 ] , Thickness [ . 01 ] } } ] , Image

If [ Mod [ n / 2 , 1 ] === 0 , Integrate [ Cos [ n x ] 2 , { x , 0 , 2 Pi } ] / 2 , Image

Integrate [ Cos [ n x ] 2 , { x , 0 , Pi } ] / 2 ] , Image

PolarPlot [ Cos [ n x ] , { x , 0 , 2 Pi } , Image

PlotRange { { 3 / 2 , 3 / 2 } , { 3 / 2 , 3 / 2 } } , AspectRatio 1 , Image

PlotStyle { { CMYKColor [ 0 , . 1 , . 48 , . 22 ] , Thickness [ . 01 ] } } ] } , { n , 1 , 4 } ] ; Image

TableForm [ t1 , Image

TableHeadings Image

{ Table [ n , { n , 1 , 4 } ] , { “Area Sine” , “Sine Plot” , “Area Cosine” , “Cosine Plot” } } ] Image

Alternatively, you can use Manipulate.

Clear [ n , x ] ; Image

Manipulate [ { n , Image

If [ Mod [ n / 2 , 1 ] === 0 , Integrate [ Sin [ n x ] 2 , { x , 0 , 2 Pi } ] / 2 , Image

Integrate [ Sin [ n x ] 2 , { x , 0 , Pi } ] / 2 ] , Image

PolarPlot [ Sin [ n x ] , { x , 0 , 2 Pi } , Image

PlotRange { { 3 / 2 , 3 / 2 } , { 3 / 2 , 3 / 2 } } , AspectRatio 1 , Image

PlotStyle Black ] , Image

If [ Mod [ n / 2 , 1 ] === 0 , Integrate [ Cos [ n x ] 2 , { x , 0 , 2 Pi } ] / 2 , Image

Integrate [ Cos [ n x ] 2 , { x , 0 , Pi } ] / 2 ] , Image

PolarPlot [ Cos [ n x ] , { x , 0 , 2 Pi } , Image

PlotRange { { 3 / 2 , 3 / 2 } , { 3 / 2 , 3 / 2 } } , AspectRatio 1 , Image

PlotStyle Black ] } , { { n , 5 } , 1 , 100 , 1 } ] Image

4.1.2 Plotting Lists of Points

Lists are plotted with ListPlot.

1.  ListPlot[{{x1,y1},{x2,y2},...,{xn,yn}}] plots the list of points {(x1,y1),(x2,y2),,(xn,yn)}Image. The size of the points in the resulting plot is controlled with the option PlotStyle->PointSize[w], where w is the fraction of the total width of the graphic. For two-dimensional graphics, the default value is 0.008.

2.  ListPlot[{y1,y2,..,yn}] plots the list of points {(1,y1),(2,y2),,Image (n,yn)}Image.

3.  ListLinePlot[{y1,y2,..,yn}] plots the list of points {(1,y1),(2,y2),,Image (n,yn)}Image and connects consecutive points with line segments. Alternatively, you can use ListPlot together with the option Joined->True to connect consecutive points with line segments.

Example 4.7

The Prime Difference Function and the Prime Number Theorem

In t1, we use Prime and Table to compute a list of the first 25,000Image prime numbers.

t1 = Table [ Prime [ n ] , { n , 1 , 25000 } ] ; Image

Length [ t1 ] Image

We use Length to verify that t1 has 25,000Image elements and Short to see an abbreviated portion of t1.

25000

Short [ t1 ] Image

{ 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 24984 , 287047 , 287057 , 287059 , 287087 , 287093 , 287099 , 287107 , 287117 } Image

You can also use Take to extract elements of lists.

1.  Take[list,n] returns the first n elements of list;

2.  Take[list,-n] returns the last n elements of list; and

3.  Take[list,{n,m}] returns the nth through mth elements of list.

First[list] returns the first element of list; Last[list] returns the last element of list.

Take [ t1 , 5 ] Image

{ 2 , 3 , 5 , 7 , 11 } Image

Take [ t1 , 5 ] Image

{ 287087 , 287093 , 287099 , 287107 , 287117 } Image

Take [ t1 , { 12501 , 12505 } ] Image

{ 134059 , 134077 , 134081 , 134087 , 134089 } Image

In t2, we compute the difference, dnImage, between the successive prime numbers in t1. The result is plotted with ListPlot in Fig. 4.4.

list[[i]] returns the ith element of list so list[[i+1]]list[[i]]Image computes the difference between the (i+1)Imagest and ith elements of list. list[[i,j]] returns the jth part of the ith part of list.

Image
Figure 4.4 A plot of the difference, dn, between successive prime numbers.

t2 = Table [ t1 [ [ i + 1 ] ] t1 [ [ i ] ] , { i , 1 , Length [ t1 ] 1 } ] ; Image

Short [ t2 ] Image

{ 1 , 2 , 2 , 4 , 2 , 4 , 2 , 4 , 6 , 2 , 6 , 4 , 2 , 4 , 6 , 6 , 2 , 6 , 24964 , 18 , 28 , 14 , 54 , 46 , 8 , 6 , 12 , 4 , 44 , 10 , 2 , 28 , 6 , 6 , 8 , 10 } Image

ListPlot [ t2 , PlotRange All , Image

PlotStyle { CMYKColor [ . 09 , 1 , . 64 , . 48 ] , PointSize [ . 01 ] } ] Image

Let π(n)Image denote the number of primes less than n and Li(x)Image denote the logarithmic integral:

L o g I n t e g r a l [ x ] = L i ( x ) = 0 x 1 ln t d t .

We use Plot to graph Li(x)Image for 1x25,000Image in p1.

Remember that p1 is not displayed because a semi-colon is included at the end of the Plot command.

p1 = Plot [ LogIntegral [ x ] , { x , 1 , 2500 } , Image

PlotStyle { { CMYKColor [ . 17 , . 36 , . 52 , . 38 ] , Thickness [ . 01 ] } } ] Image

The Prime Number Theorem states that

π ( n ) L i ( n ) .

(See [17].) In the following, we use Select and Length to define π(n)Image. Select[list,criteria] returns the elements of list for which criteria is true. Note that #<n is called a pure function: given an argument #, #<n is true if #<n and false otherwise. The & symbol marks the end of a pure function. Thus, given n, Select[t1,#<n&] returns a list of the elements of t1 less than n; Select[t1,#<n&]//Length returns the number of elements in the list.

smallpi [ n _ ] := Select [ t1 , # < n & ] // Length Image

For example,

smallpi [ 100 ] Image

25

shows us that π(100)=25Image. Note that because t1 contains the first 25,000Image primes, smallpi[n] is valid for 1nNImage where π(N)=25,000Image. In t3, we compute π(n)Image for n=1Image, 2, …, 2500

t3 = Table [ smallpi [ n ] , { n , 1 , 2500 } ] ; Image

Short [ t3 ] Image

{ 0 , 0 , 1 , 2 , 2 , 3 , 3 , 4 , 4 , 4 , 4 , 5 , 5 , 6 , 2473 , 367 , 367 , 367 , 367 , 367 , 367 , 367 , 367 , 367 , 367 , 367 , 367 , 367 } Image

and plot the resulting list with ListPlot.

p2 = ListPlot [ t3 , PlotStyle CMYKColor [ . 05 , . 71 , 1 , . 23 ] ] Image

p1 and p2 are displayed together with Show in Fig. 4.5.

Image
Figure 4.5 Graphs of Li(x) and π(n).

Show [ p1 , p2 ] Image

Working in almost the same way as Take, Span (;;) selects elements of lists: list[[n;;m]] returns the n through mth elements of list.

Span is new Mathematica 11 but works in almost the same way as Take.

Example 4.8

Here are the first few terms of sequence A073184 (N.J.A. Sloane, 2007, The On-Line Encyclopedia of Integer Sequences, www.research.att.com/njas/sequences/), the number of cube free divisors of n.

ashortlist = { 1 , 2 , 2 , 3 , 2 , 4 , 2 , 3 , 3 , 4 , 2 , 6 , Image

2 , 4 , 4 , 3 , 2 , 6 , 2 , 6 , 4 , 4 , 2 , 6 , Image

3 , 4 , 3 , 6 , 2 , 8 , 2 , 3 , 4 , 4 , 4 } ; Image

With ;; (Span), we select the 2nd through 8th elements of ashortlist.

ashortlist [ [ 2 ;; 8 ] ] Image

{ 2 , 2 , 3 , 2 , 4 , 2 , 3 } Image

The same results are obtained with Take.

Take [ ashortlist , { 2 , 8 } ] Image

{ 2 , 2 , 3 , 2 , 4 , 2 , 3 } Image

You can count the number of elements of a list with Length.

Length [ ashortlist ] Image

35

With Tally, we count the number of occurrences of each digit in the list. Thus,

Tally [ ashortlist ] Image

{ { 1 , 1 } , { 2 , 11 } , { 3 , 7 } , { 4 , 10 } , { 6 , 5 } , { 8 , 1 } } Image

shows us that there are 11 2's, 10 4's, and so on.

However, you can use Table together with Part ([[...]]) to obtain the same results as those obtained with Take or Span.

Table [ t1 [ [ i ] ] , { i , 1 , 5 } ] Image

Table [ t1 [ [ i ] ] , { i , 24996 , 25000 } ] Image

Table[t1[[i]],{i,12501,12505}]Image

{ 2 , 3 , 5 , 7 , 11 } Image

{ 287087 , 287093 , 287099 , 287107 , 287117 } Image

{ 134059 , 134077 , 134081 , 134087 , 134089 } Image

You can iterate recursively with Table. Both

{ { a [ 1 , 2 ] , a [ 2 , 2 ] , a [ 3 , 2 ] , a [ 4 , 2 ] , a [ 5 , 2 ] } , { a [ 1 , 4 ] , a [ 2 , 4 ] , a [ 3 , 4 ] , a [ 4 , 4 ] , a [ 5 , 4 ] } , Image

{ a [ 1 , 6 ] , a [ 2 , 6 ] , a [ 3 , 6 ] , a [ 4 , 6 ] , a [ 5 , 6 ] } , { a [ 1 , 8 ] , a [ 2 , 8 ] , a [ 3 , 8 ] , a [ 4 , 8 ] , a [ 5 , 8 ] } , Image

{ a [ 1 , 10 ] , a [ 2 , 10 ] , a [ 3 , 10 ] , a [ 4 , 10 ] , a [ 5 , 10 ] } } Image

Length [ t1 ] Image

5

and

t2 = Table [ Table [ a [ i , j ] , { i , 1 , 5 } ] , { j , 2 , 10 , 2 } ] Image

{ { a [ 1 , 2 ] , a [ 2 , 2 ] , a [ 3 , 2 ] , a [ 4 , 2 ] , a [ 5 , 2 ] } , { a [ 1 , 4 ] , a [ 2 , 4 ] , a [ 3 , 4 ] , a [ 4 , 4 ] , a [ 5 , 4 ] } , { a [ 1 , 6 ] , a [ 2 , 6 ] , a [ 3 , 6 ] , a [ 4 , 6 ] , a [ 5 , 6 ] } , { a [ 1 , 8 ] , a [ 2 , 8 ] , a [ 3 , 8 ] , a [ 4 , 8 ] , a [ 5 , 8 ] } , { a [ 1 , 10 ] , a [ 2 , 10 ] , a [ 3 , 10 ] , a [ 4 , 10 ] , a [ 5 , 10 ] } } Image

compute tables of aijImage. The outermost iterator is evaluated first: in this case, i is followed by j as in t1 and the result is a list of lists. To eliminate the inner lists (that is, the braces), use Flatten. Generally, Flatten[list,n] flattens list (removes braces) to level n.

Flatten [ t1 ] Image

{ a [ 1 , 2 ] , a [ 2 , 2 ] , a [ 3 , 2 ] , a [ 4 , 2 ] , a [ 5 , 2 ] , a [ 1 , 4 ] , a [ 2 , 4 ] , a [ 3 , 4 ] , a [ 4 , 4 ] , a [ 5 , 4 ] , a [ 1 , 6 ] , a [ 2 , 6 ] , a [ 3 , 6 ] , a [ 4 , 6 ] , a [ 5 , 6 ] , a [ 1 , 8 ] , a [ 2 , 8 ] , a [ 3 , 8 ] , a [ 4 , 8 ] , a [ 5 , 8 ] , a [ 1 , 10 ] , a [ 2 , 10 ] , a [ 3 , 10 ] , a [ 4 , 10 ] , a [ 5 , 10 ] } Image

The observation is especially important when graphing lists of points obtained by iterating Table. For example,

Length[list] returns the number of elements in list.

t1 = Table [ { Sin [ x + y ] , Cos [ x y ] } , { x , 1 , 5 } , { y , 1 , 5 } ] Image

{ { { Sin [ 2 ] , 1 } , { Sin [ 3 ] , Cos [ 1 ] } , { Sin [ 4 ] , Cos [ 2 ] } , { Sin [ 5 ] , Cos [ 3 ] } , { Sin [ 6 ] , Cos [ 4 ] } } , { { Sin [ 3 ] , Cos [ 1 ] } , { Sin [ 4 ] , 1 } , { Sin [ 5 ] , Cos [ 1 ] } , { Sin [ 6 ] , Cos [ 2 ] } , { Sin [ 7 ] , Cos [ 3 ] } } , { { Sin [ 4 ] , Cos [ 2 ] } , { Sin [ 5 ] , Cos [ 1 ] } , { Sin [ 6 ] , 1 } , { Sin [ 7 ] , Cos [ 1 ] } , { Sin [ 8 ] , Cos [ 2 ] } } , { { Sin [ 5 ] , Cos [ 3 ] } , { Sin [ 6 ] , Cos [ 2 ] } , { Sin [ 7 ] , Cos [ 1 ] } , { Sin [ 8 ] , 1 } , { Sin [ 9 ] , Cos [ 1 ] } } , { { Sin [ 6 ] , Cos [ 4 ] } , { Sin [ 7 ] , Cos [ 3 ] } , { Sin [ 8 ] , Cos [ 2 ] } , { Sin [ 9 ] , Cos [ 1 ] } , { Sin [ 10 ] , 1 } } } Image

Length [ t1 ] Image

5

is not a list of 25 points: t1 is a list of 5 lists each consisting of 5 points. t1 has two levels. For example, the 3rd element of the second level is

t1 [ [ 3 ] ] Image

{ { Sin [ 4 ] , Cos [ 2 ] } , { Sin [ 5 ] , Cos [ 1 ] } , { Sin [ 6 ] , 1 } , { Sin [ 7 ] , Cos [ 1 ] } , { Sin [ 8 ] , Cos [ 2 ] } } Image

and the 2nd element of the third level (or the second part of the third part) is

t1 [ [ 3 , 2 ] ] Image

{ Sin [ 5 ] , Cos [ 1 ] } Image

To flatten t2 to level 1, we use Flatten.

t2 = Flatten [ t1 , 1 ] Image

{ { Sin [ 2 ] , 1 } , { Sin [ 3 ] , Cos [ 1 ] } , { Sin [ 4 ] , Cos [ 2 ] } , { Sin [ 5 ] , Cos [ 3 ] } , { Sin [ 6 ] , Cos [ 4 ] } , { Sin [ 3 ] , Cos [ 1 ] } , { Sin [ 4 ] , 1 } , { Sin [ 5 ] , Cos [ 1 ] } , { Sin [ 6 ] , Cos [ 2 ] } , { Sin [ 7 ] , Cos [ 3 ] } , { Sin [ 4 ] , Cos [ 2 ] } , { Sin [ 5 ] , Cos [ 1 ] } , { Sin [ 6 ] , 1 } , { Sin [ 7 ] , Cos [ 1 ] } , { Sin [ 8 ] , Cos [ 2 ] } , { Sin [ 5 ] , Cos [ 3 ] } , { Sin [ 6 ] , Cos [ 2 ] } , { Sin [ 7 ] , Cos [ 1 ] } , { Sin [ 8 ] , 1 } , { Sin [ 9 ] , Cos [ 1 ] } , { Sin [ 6 ] , Cos [ 4 ] } , { Sin [ 7 ] , Cos [ 3 ] } , { Sin [ 8 ] , Cos [ 2 ] } , { Sin [ 9 ] , Cos [ 1 ] } , { Sin [ 10 ] , 1 } } Image

The resulting list of ordered pairs (in Mathematica, {x,y} corresponds to (x,y)Image). This list of points are then plotted with ListPlot in Fig. 4.6 (a). We also illustrate the use of the PlotStyle, PlotRange, and AspectRatio options in the ListPlot command.

Image
Figure 4.6 (a) and (b). (Rutgers University colors)

lp1 = ListPlot [ t2 , PlotStyle { PointSize [ . 05 ] , CMYKColor [ . 11 , 0 , 0 , . 64 ] } , Image

PlotRange { { 3 / 2 , 3 / 2 } , { 3 / 2 , 3 / 2 } } , AspectRatio Automatic , Image

PlotLabel “(a)” ] ; Image

Increasing the number of points further illustrates the use of Flatten. Entering

t1 = Table [ { Sin [ x + y ] , Cos [ x y ] } , { x , 1 , 125 } , { y , 1 , 125 } ] ; Image

Length [ t1 ] Image

125

results in a very long nested list. t1 has 125 elements each of which has 125 elements.

An abbreviated version is viewed with Short.

Short[list] yields an abbreviated version of list.

Short [ t1 ] Image

{ { { Sin [ 2 ] , 1 } , { Sin [ 3 ] , Cos [ 1 ] } , 121 , { Sin [ 125 ] , Cos [ 123 ] } , { Sin [ 126 ] , Cos [ 124 ] } } , 123 , { 1 } } Image

After using Flatten, we see with Length and Short that t2 contains 15, 625 points,

t2 = Flatten [ t1 , 1 ] ; Image

Length [ t2 ] Image

15625

Short [ t2 ] Image

{ { Sin [ 2 ] , 1 } , { Sin [ 3 ] , Cos [ 1 ] } , 15621 , { Sin [ 249 ] , Cos [ 1 ] } , { Sin [ 250 ] , 1 } } Image

which are plotted with ListPlot in Fig. 4.6 (b).

lp2 = ListPlot [ t2 , PlotStyle { { CMYKColor [ 0 , 1 , . 81 , . 04 ] } } , AspectRatio Automatic , Image

PlotLabel “(b)” ] ; Image

Show [ GraphicsRow [ { lp1 , lp2 } ] ] Image

Remark 4.2

Mathematica is very flexible and most calculations can be carried out in more than one way. Depending on how you think, some sequences of calculations may make more sense to you than others, even if they are less efficient than the most efficient way to perform the desired calculations. Often, the difference in time required for Mathematica to perform equivalent – but different – calculations is quite small. For the beginner, we think it is wisest to work with familiar calculations first and then efficiency.

Example 4.9

Dynamical Systems

A sequence of the form xn+1=f(xn)Image is called a dynamical system.

Observe that xn+1=f(xn)Image can also be computed with xn+1=fn(x0)Image.

Sometimes, unusual behavior can be observed when working with dynamical systems. For example, consider the dynamical system with f(x)=x+2.5x(1x)Image and x0=1.2Image. Note that we define xnImage using the form x[n_]:=x[n]=... so that Mathematica “remembers” the functional values it computes and thus avoids recomputing functional values previously computed. This is particularly advantageous when we compute the value of xnImage for large values of n.

Clear [ f , x ] Image

f [ x _ ] := x + 2.5 x ( 1 x ) Image

x [ n _ ] := x [ n ] = f [ x [ n 1 ] ] Image

x [ 0 ] = 1.2 ; Image

In Fig. 4.7 (a), we see that the sequence xnImage oscillates between the numbers 0.6 and 1.2. We say that the dynamical system has a 2-cycle because the values of the sequence oscillate between two numbers.

Image
Figure 4.7 (a) A 2-cycle. (b) A 4-cycle. (University of Notre Dame colors)

tb = Table [ x [ n ] , { n , 1 , 200 } ] ; Image

ListPlot [ tb , PlotStyle CMYKColor [ 1 , . 76 , . 12 , . 7 ] , Image

PlotLabel “(a)” ] Image

In Fig. 4.7 (b), we see that changing x0Image from 1.2 to 1.201 results in a 4-cycle.

Clear [ f , x ] Image

f [ x _ ] := x + 2.5 x ( 1 x ) Image

x [ n _ ] := x [ n ] = f [ x [ n 1 ] ] Image

x [ 0 ] = 1.201 ; Image

tb = Table [ x [ n ] , { n , 1 , 200 } ] ; Image

Short [ tb , 20 ] Image

{ 0.597497 , 1.19873 , 0.603163 , 1.20156 , 0.596102 , 1.19801 , 0.604957 , 1.20242 , 0.593943 , 1.19688 , 0.607777 , 1.20374 , 0.590622 , 1.19509 , 0.612212 , 1.20573 , 0.585585 , 1.19227 , 0.619168 , 1.20867 , 0.578149 , 1.18788 , 0.629931 , 1.21273 , 0.567781 , 1.1813 , 0.645888 , 1.21768 , 0.55502 , 1.17245 , 0.666974 , 1.22227 , 0.543077 , 1.16344 , 0.688063 , 131 , 0.701238 , 1.225 , 0.535948 , 1.15772 , 0.701238 , 1.225 , 0.535948 , 1.15772 , 0.701238 , 1.225 , 0.535948 , 1.15772 , 0.701238 , 1.225 , 0.535948 , 1.15772 , 0.701238 , 1.225 , 0.535948 , 1.15772 , 0.701238 , 1.225 , 0.535948 , 1.15772 , 0.701238 , 1.225 , 0.535948 , 1.15772 , 0.701238 , 1.225 , 0.535948 , 1.15772 , 0.701238 , 1.225 } Image

ListPlot [ tb , PlotStyle CMYKColor [ . 06 , . 27 , 1 , . 12 ] , PlotLabel “(b)” ] Image

The calculations indicate that the behavior of the system can change considerably for small changes in x0Image. With the following, we adjust the definition of x so that x depends on x0=cImage: given c, xc(0)=cImage.

Clear [ f , x ] Image

f [ x _ ] := x + 2.5 x ( 1 x ) Image

x [ c _ ] [ n _ ] := x [ c ] [ n ] = f [ x [ c ] [ n 1 ] ] // N Image

x [ c _ ] [ 0 ] := c // N ; Image

In tb, we create a list of lists of the form {xc(n)|n=100,,150}Image for 150 equally spaced values of c between 0 and 1.5. Observe that Mathematica issues several error messages. When a Mathematica calculation is larger than the machine's precision, we obtain an Overflow warning. In numerical calculations, we interpret Overflow to correspond to ∞.

tb = Table [ { c , x [ c ] [ n ] } , { c , 0 , 1.5 , . 01 } , { n , 100 , 150 } ] ; Image

General :: ovfl Image

General :: ovfl Image

General :: ovfl Image

General :: stop Image

We ignore the error messages and use Short to view an abbreviated form of tb.

Short[expr] prints an abbreviated form of expr.

Short [ tb ] Image

{ { { 0 . , 0 . } , { 0 . , 0 . } , { 0 . , 0 . } , 45 , { 0 . , 0 . } , { 0 . , 0 . } , { 0 . , 0 . } } , { 1 } , 147 , { 1 } , { 1 } } Image

We then use Flatten to convert tb to a list of points which are plotted with ListPlot in Fig. 4.8 (a).

Image
Figure 4.8 (a) and (b).

tb2 = Flatten [ tb , 1 ] ; Image

f1 = ListPlot [ tb2 , PlotStyle CMYKColor [ . 31 , . 39 , . 89 , . 06 ] , Image

PlotLabel“(a)”]Image

Another interesting situation occurs if we fix x0Image and let c vary in f(x)=x+cx(1x)Image.

With the following we set x0=1.2Image and adjust the definition of f so that f depends on c: f(x)=x+cx(1x)Image.

Clear [ f , x ] Image

f [ c _ ] [ x _ ] := x + c   x ( 1 x ) // N Image

x [ c _ ] [ n _ ] := x [ c ] [ n ] = f [ c ] [ x [ c ] [ n 1 ] ] // N Image

x [ c _ ] [ 0 ] := 1.2 // N ; Image

In tb, we create a list of lists of the form {xc(n)|n=200,,300}Image for 350 equally spaced values of c between 0 and 3.5. As before, Mathematica issues several error messages, which we ignore.

tb = Table [ { c , x [ c ] [ n ] } , { c , 0 , 3.5 , . 01 } , { n , 200 , 300 } ] ; Image

General :: ovfl Image

General :: ovfl Image

General :: ovfl Image

General :: stop Image

Short [ tb ] Image

{ { { 0 . , 1.2 } , { 0 . , 1.2 } , { 0 . , 1.2 } , 95 , { 0 . , 1.2 } , { 0 . , 1.2 } , { 0 . , 1.2 } } , 349 , { 1 } } Image

tb is then converted to a list of points with Flatten and the resulting list is plotted in Fig. 4.8 (b) with ListPlot. This plot is called a bifurcation diagram.

tb2 = Flatten [ tb , 1 ] ; Image

f2 = ListPlot [ tb2 , PlotStyle CMYKColor [ 1 , . 76 , . 12 , . 7 ] , Image

PlotRange { 0 , 2 } , PlotLabel “(b)” ] Image

Show [ GraphicsRow [ { f1 , f2 } ] ] Image

As indicated earlier, elements of lists can be numbers, ordered pairs, functions, and even other lists. You can also use Mathematica to manipulate lists in numerous ways. Most importantly, the Map function is used to apply a function to a list: Map[f,{x1,x2,...,xn}] returns the list {f(x1),f(x2),,f(xn)}Image. We will discuss other operations that can be performed on lists in the following sections.

A function f is listable if f[list] and Map[f,list] return the same results.

Solution

We proceed by using HermiteH together with Table to define hermitetable to be the list consisting of the first five Hermite polynomials.

hermitetable = Table [ HermiteH [ n , x ] , { n , 1 , 5 } ] Image

{ 2 x , 2 + 4 x 2 , 12 x + 8 x 3 , 12 48 x 2 + 16 x 4 , 120 x 160 x 3 + 32 x 5 } Image

We then use ReplaceAll (->) to evaluate each member of hermitetable if x is replaced by 1.

hermitetable /. x 1 Image

{ 2 , 2 , 4 , 20 , 8 } Image

Functions like D and Integrate are listable. A function is listable if it automatically passes through a list. For example, since D is listable, the command D[listoffunctions,x] will return a list of the derivative of the list listoffunctions with respect to x. Thus, each of the following commands differentiate each element of hermitetable with respect to x. In the second case, we have used a pure function: given an argument #, D[#,x]& differentiates # with respect to x. Use the & symbol to indicate the end of a pure function.

D [ hermitetable , x ] Image

{ 2 , 8 x , 12 + 24 x 2 , 96 x + 64 x 3 , 120 480 x 2 + 160 x 4 } Image

Map [ D [ # , x ] & , hermitetable ] Image

{2,8x,12+24x2,96x+64x3,120480x2+160x4}Image

Similarly, we use Integrate to antidifferentiate each member of hermitetable with respect to x. Remember that Mathematica does not automatically include the “+C” that we include when we antidifferentiate.

Integrate [ hermitetable , x ] Image

{ x 2 , 2 x + 4 x 3 3 , 4 ( 3 x 2 2 + x 4 2 ) , 4 ( 3 x 4 x 3 + 4 x 5 5 ) , 8 ( 15 x 2 2 5 x 4 + 2 x 6 3 ) } Image

Map [ Integrate [ # , x ] & , hermitetable ] Image

{ x 2 , 2 x + 4 x 3 3 , 4 ( 3 x 2 2 + x 4 2 ) , 4 ( 3 x 4 x 3 + 4 x 5 5 ) , 8 ( 15 x 2 2 5 x 4 + 2 x 6 3 ) } Image

To graph the list hermitetable, we use Plot to plot each function in the set hermitetable on the interval [2,2]Image in Fig. 4.9. In this case, we specify that the displayed y-values correspond to the interval [−20, 20]. Because we apply Tooltip to the set of functions being plotted, you can identify each curve by moving the cursor and placing it over each curve to see which function is being plotted.

Image
Figure 4.9 Graphs of H1(x), H2(x), H3(x), H4(x), and H5(x).

Plot [ Tooltip [ Evaluate [ hermitetable ] ] , { x , 1 , 1 } , PlotRange { 20 , 20 } ] Image

hermitetable[[n]] returns the nth element of hermitetable, which corresponds to Hn(x)Image. Thus,

verifyde = Table [ D [ hermitetable [ [ n ] ] , { x , 2 } ] 2 x D [ hermitetable [ [ n ] ] , x ] + Image

2 n hermitetable [ [ n ] ] // Simplify , { n , 1 , 5 } ] Image

{ 0 , 0 , 0 , 0 , 0 } Image

computes and simplifies Hn2xHn+2nHnImage for n=1Image, 2, …, 5. We use Table and Integrate to compute Hn(x)Hm(x)ex2dxImage for n=1Image, 2, …, 5 and m=1Image, 2,,5Image.

verifyortho = Table [ Integrate [ hermitetable [ [ n , 2 ] ] hermitetable [ [ m , 2 ] ] Image

Exp [ x 2 ] , { x , Infinity , Infinity } ] , { n , 1 , 5 } , { m , 1 , 5 } ] Image

{{π2,0,6π,0,120π},{0,12π,0,144π,0},{6π,0,120π,0,2400π},{0,144π,0,1728π,0},{120π,0,2400π,0,48000π}}Image

To view a table in traditional row-and-column form use TableForm, as we do here illustrating the use of the TableHeadings option.

TableForm [ verifyortho , Image

TableHeadings { { “m=1” , “m=2” , “m=3” , “m=4” , “m=5” } , Image

{ “n=1” , “n=2” , “n=3” , “n=4” , “n=5” } } ] Image

n = 1 n = 2 n = 3 n = 4 n = 5 m = 1 π 2 0 6 π 0 120 π m = 2 0 12 π 0 144 π 0 m = 3 6 π 0 120 π 0 2400 π m = 4 0 144 π 0 1728 π 0 m = 5 120 π 0 2400 π 0 48000 π Image

Be careful when using TableForm: TableForm[table] is no longer a list and cannot be manipulated like a list.  □

4.2 Manipulating Lists: More on Part and Map

Often, Mathematica's output is given to us as a list that we need to use in subsequent calculations. Elements of a list are extracted with Part ([[...]]): list[[i]] returns the ith element of list; list[[i,j]] (or list[[i]][[j]]) returns the jth element of the ith element of list, and so on.

Example 4.11

Let f(x)=3x48x330x2+72xImage. Locate and classify the critical points of y=f(x)Image.

Solution

We begin by clearing all prior definitions of f and then defining f(x)=3x48x330x2+72xImage. The critical numbers are found by solving the equation f(x)=0Image. The resulting list is named critnums.

Clear [ f ] Image

f [ x _ ] = 3 x 4 8 x 3 30 x 2 + 72 x ; Image

critnums = Solve [ f [ x ] == 0 ] Image

{ { x 2 } , { x 1 } , { x 3 } } Image

critnums is actually a list of lists. For example, the number −2 is the second part of the first part of the second part of critnums.

critnums[[1]]Image

{ x 2 } Image

critnums [ [ 1 , 1 ] ] Image

x 2 Image

critnums [ [ 1 , 1 , 2 ] ] Image

−2

Similarly, the numbers 1 and 3 are extracted with critnums[[2,1,2]] and

critnums[[3,1,2]], respectively.

critnums [ [ 2 , 1 , 2 ] ] Image

critnums [ [ 3 , 1 , 2 ] ] Image

1

3

We locate and classify the points by evaluating f(x)Image and f(x)Image for each of the numbers in critnums. f[x]/.x->a replaces each occurrence of x in f(x)Image by a, so entering

{ x , f [ x ] , f [ x ] } /. critnums // TableForm Image

2 152 180 1 37 72 3 27 120 Image

replaces each x in the list {x,f(x),f(x)}Image by each of the x-values in critnums.

By the Second Derivative Test, we conclude that y=f(x)Image has relative minima at the points (2,152)Image and (3,27)Image while f(x)Image has a relative maximum at (1,37)Image. In fact, because limx±f(x)=Image, −152 is the absolute minimum value of f(x)Image. These results are confirmed by the graph of y=f(x)Image in Fig. 4.10.

Image
Figure 4.10 Graph of f(x)=3x4 − 8x3 − 30x2 + 72x, f(x), and f(x). (University of Rochester colors)

When you plot lists of functions and apply Tooltip to the list being plotted, you can identify each curve by sliding the cursor over the curve. When the cursor is on a curve, the definition of the curve being plotted is displayed.

Plot [ Tooltip [ { f [ x ] , f [ x ] , f [ x ] } ] , { x , 4 , 4 } , Image

PlotStyle { { CMYKColor [ 0 , . 1 , 1 , 0 ] , Thickness [ . 01 ] } , Image

{ CMYKColor [ 1 , . 57 , 0 , . 38 ] , Thickness [ . 01 ] } , Image

{ CMYKColor [ 0 , 0 , 0 , . 17 ] , Thickness [ . 01 ] } } , Image

AspectRatio1,AxesLabel{x,y}]Image □

Map is a very powerful and useful function: Map[f,list] creates a list consisting of elements obtained by evaluating f for each element of list, provided that each member of list is an element of the domain of f. Note that if f is listable, f[list] produces the same result as Map[f,list].

To determine if f is listable, enter Attributes[f].

Example 4.12

Entering

t1 = Table [ n , { n , 1 , 100 } ] ; Image

t1b = Partition [ t1 , 10 ] ; Image

TableForm [ t1b ] Image

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 Image

computes a list of the first 100 integers and names the result t1. To see t1, we use Partition to partition t1 in 10 element subsets; the results are displayed in a standard row-and-column form with TableForm. We then define f(x)=x2Image and use Map to square each number in t1.

f [ x _ ] = x 2 ; Image

t2 = Map [ f , t1 ] ; Image

t2b = Partition [ t2 , 10 ] ; Image

TableForm [ t2b ] Image

1 4 9 16 25 36 49 64 81 100 121 144 169 196 225 256 289 324 361 400 441 484 529 576 625 676 729 784 841 900 961 1024 1089 1156 1225 1296 1369 1444 1521 1600 1681 1764 1849 1936 2025 2116 2209 2304 2401 2500 2601 2704 2809 2916 3025 3136 3249 3364 3481 3600 3721 3844 3969 4096 4225 4356 4489 4624 4761 4900 5041 5184 5329 5476 5625 5776 5929 6084 6241 6400 6561 6724 6889 7056 7225 7396 7569 7744 7921 8100 8281 8464 8649 8836 9025 9216 9409 9604 9801 10000 Image

The same result is accomplished by the pure function that squares its argument. Note how # denotes the argument of the pure function; the & symbol marks the end of the pure function.

t3 = Map [ # 2 & , t1 ] ; Image

t3b = Partition [ t3 , 10 ] ; Image

TableForm [ t3b ] Image

1491625364964811001211441691962252562893243614004414845295766256767297848419009611024108911561225129613691444152116001681176418491936202521162209230424012500260127042809291630253136324933643481360037213844396940964225435644894624476149005041518453295476562557765929608462416400656167246889705672257396756977447921810082818464864988369025921694099604980110000Image

On the other hand, entering

t1 = Table [ { a , b } , { a , 1 , 5 } , { b , 1 , 5 } ] ; Image

Short [ t1 ] Image

{ { { 1 , 1 } , { 1 , 2 } , { 1 , 3 } , { 1 , 4 } , { 1 , 5 } } , { 1 } , 1 , { 1 } , { { 5 , 1 } , { 5 , 2 } , { 5 , 3 } , { 5 , 4 } , { 5 , 5 } } } Image

is a list (of length 5) of lists (each of length 5). Use Flatten to obtain a list of 25 points, which we name t2.

t2 = Flatten [ t1 , 1 ] ; Image

Short [ t2 ] Image

{ { 1 , 1 } , { 1 , 2 } , { 1 , 3 } , { 1 , 4 } , { 1 , 5 } , { 2 , 1 } , 13 , { 4 , 5 } , { 5 , 1 } , { 5 , 2 } , { 5 , 3 } , { 5 , 4 } , { 5 , 5 } } Image

We then use Map to apply f to t2.

f [ { x _ , y _ } ] = { { x , y } , x 2 + y 2 } ; Image

t3 = Map [ f , t2 ] ; Image

Short [ t3 ] Image

{ { { 1 , 1 } , 2 } , { { 1 , 2 } , 5 } , { { 1 , 3 } , 10 } , 19 , { { 5 , 3 } , 34 } , { { 5 , 4 } , 41 } , { { 5 , 5 } , 50 } } Image

We accomplish the same result with a pure function. Observe how #[[1]] and #[[2]] are used to represent the first and second arguments: given a list of length 2, the pure function returns the list of ordered pairs consisting of the first element of the list, the second element of the list (as an ordered pair), and the sum of the squares of the first and second elements (of the first ordered pair).

t3b = Map [ { { # [ [ 1 ] ] , # [ [ 2 ] ] } , # [ [ 1 ] ] 2 + # [ [ 2 ] ] 2 } & , t2 ] ; Image

Short [ t3b ] Image

{ { { 1 , 1 } , 2 } , { { 1 , 2 } , 5 } , { { 1 , 3 } , 10 } , 19 , { { 5 , 3 } , 34 } , { { 5 , 4 } , 41 } , { { 5 , 5 } , 50 } } Image

Example 4.13

Make a table of the values of the trigonometric functions y=sinxImage, y=cosxImage, and y=tanxImage for the principal angles.

Solution

We first construct a list of the principal angles which is accomplished by defining t1 to be the list consisting of nπ/4Image for n=0Image, 1, …, 8 and t2 to be the list consisting of nπ/6Image for n=0Image, 1, …, 12. The principal angles are obtained by taking the union of t1 and t2. Union[t1,t2] joins the lists t1 and t2, removes repeated elements, and sorts the results. If we did not wish to remove repeated elements and sort the result, the command Join[t1,t2] concatenates the lists t1 and t2.

t1 = Table [ n π 4 , { n , 0 , 8 } ] ; Image

t2 = Table [ n π 6 , { n , 0 , 12 } ] ; Image

prinangles = Union [ t1 , t2 ] Image

{ 0 , π 6 , π 4 , π 3 , π 2 , 2 π 3 , 3 π 4 , 5 π 6 , π , 7 π 6 , 5 π 4 , 4 π 3 , 3 π 2 , 5 π 3 , 7 π 4 , 11 π 6 , 2 π } Image

We can also use the symbol ∪, which is obtained by clicking on the Image button on the BasicMathInput palette to represent Union.

The BasicMathInput palette:

Image

prinangles = t1 t2 Image

{ 0 , π 6 , π 4 , π 3 , π 2 , 2 π 3 , 3 π 4 , 5 π 6 , π , 7 π 6 , 5 π 4 , 4 π 3 , 3 π 2 , 5 π 3 , 7 π 4 , 11 π 6 , 2 π } Image

Next, we define f(x)Image to be the function that returns the ordered quadruple

( x , sin x , cos x , tan x )

and compute the value of f(x)Image for each number in prinangles with Map naming the resulting table prinvalues. prinvalues is not displayed because a semi-colon is included at the end of the command.

Clear [ f ] Image

f [ x _ ] = { x , Sin [ x ] , Cos [ x ] , Tan [ x ] } ; Image

prinvalues = Map [ f , prinangles ] ; Image

Finally, we use TableForm illustrating the use of the TableHeadings option to display prinvalues in row-and-column form; the columns are labeled x, sinxImage, cosxImage, and tanxImage.

Remember that the result of using TableForm is not a list so cannot be manipulated like lists.

TableForm [ prinvalues , TableHeadings { None , { x , “sin(x)” , “cos(x)” , “tan(x)” } } ] Image

Image

In the table, note that y=tanxImage is undefined at odd multiples of π/2Image and Mathematica appropriately returns ComplexInfinity at those values of x for which y=tanxImage is undefined.  □

Remark 4.3

The result of using TableForm is not a list (or table) and calculations on it using commands like Map cannot be performed. TableForm helps you see results in a more readable format. To avoid confusion, do not assign the results of using TableForm any name: adopting this convention avoids any possible attempted manipulation of TableForm objects.

object=name assigns the object object the name name.

We can use Map on any list, including lists of functions and/or other lists. Remember that if the function f is listable, Map[f,list] and f[list] produce the same result.

Lists of functions are graphed with Plot: Plot[listoffunctions,{x,a,b}] graphs the list of functions of x, listoffunctions, for axbImage. If the command is entered as Plot[Tooltip[listoffunctions],{x,a,b}], you can identify the curves in the plot by moving the cursor over the curves in the graphic.

Example 4.14

Bessel Functions

The Bessel functions of the first kind, Jn(x)Image, are nonsingular solutions of x2y+xy+(x2n2)y=0Image. BesselJ[n,x] returns Jn(x)Image. Graph Jn(x)Image for n=0Image, 1, 2, …, 8.

Solution

In t1, we use Table and BesselJ to create a list of Jn(x)Image for n=0Image, 1, 2, …, 8.

t1 = Table [ BesselJ [ n , x ] , { n , 0 , 8 } ] ; Image

We then use Plot to graph each function in t1 in Fig. 4.11. You can identify each curve by sliding the cursor over each.

Image
Figure 4.11 Graphs of Jn(x) for n = 0, 1, 2, …, 8.

Plot [ Tooltip [ Evaluate [ t1 ] ] , { x , 0 , 25 } ] Image

A different effect is achieved by graphing each function separately. To do so, we define the function pfunc. Given a function of x, f, pfunc[f] plots the function for 0x100Image. The resulting graphic is not displayed because the option DisplayFunction->Identity is included in the Plot command. We then use Map to apply pfunc to each element of t1. The result is a list of 9 graphics objects, which we name t2. A nice way to display 9 graphics is as a 3×3Image array so we use Partition to convert t2 from a list of length 9 to a list of lists, each with length 3 – a 3×3Image array. Partition[list,n] returns a list of lists obtained by partitioning list into n-element subsets.

Think of Flatten and Partition as inverse functions.

pfunc [ f _ ] := Plot [ f , { x , 0 , 100 } ] ; Image

t2 = Map [ pfunc , t1 ] ; Image

t3 = Partition [ t2 , 3 ] ; Image

Instead of defining pfunc, you can use a pure function instead. The following accomplishes the same result. We display t3 using Show together with GraphicsGrid in Fig. 4.12.

Image
Figure 4.12 In the first row, from left to right, graphs of J0(x), J1(x), and J2(x); in the second row, from left to right, graphs of J3(x), J4(x), and J5(x); in the third row, from left to right, graphs of J6(x), J7(x), and J8(x). (Case Western Reserve University colors)

t2 = ( Plot [ # 1 , { x , 0 , 100 } , PlotStyle CMYKColor [ 1 , . 47 , . 12 , . 62 ] , Image

AspectRatio 1 ] & ) /@ t1 ; Image

t3 = Partition [ t2 , 3 ] ; Image

Show[GraphicsGrid[t3]]Image □

Example 4.15

Dynamical Systems

Let fc(x)=x2+cImage and consider the dynamical system given by x0=0Image and xn+1=fc(xn)Image. Generate a bifurcation diagram of fcImage.

Solution

First, recall that Nest[f,x,n] computes the repeated composition fn(x)Image. Then, in terms of a composition,

x n + 1 = f c ( x n ) = f c n ( 0 ) .

We will compute fcn(0)Image for various values of c and “large” values of n so we begin by defining cvals to be a list of 300 equally spaced values of c between −2.5 and 1.

cvals = Table [ c , { c , 2.5 , 1 . , 3.5 / 299 } ] ; Image

We then define fc(x)=x2+cImage. For a given value of c, f[c] is a function of one variable, x, while the form f[c_][x_]:=... results in a function of two variables that we think of as an indexed function that might represented using traditional mathematical notation as fc(x)Image.

Clear [ f ] Image

f [ c _ ] [ x _ ] := x 2 + c Image

To iterate fcImage for various values of c, we define h. For a given value of c, h(c)Image returns the list of points {(c,fc100(0)),(c,fc101(0)),,(c,fc200(0))}Image.

h [ c _ ] := { Table [ { c , Nest [ f [ c ] , 0 , n ] } , { n , 100 , 500 } ] } Image

We then use Map to apply h to the list cvals. Observe that Mathematica generates several error messages when numerical precision is exceeded. We choose to disregard the error messages.

t1 = Map [ h , cvals ] ; Image

t1 is a list (of length 300) of lists (each of length 101). To obtain a list of points (or, lists of length 2), we use Flatten. The resulting set of points is plotted with ListPlot in Fig. 4.13. Observe that Mathematica again displays several error messages, which are not displayed here for length considerations, that we ignore: Mathematica only plots the points with real coordinates and ignores those containing Overflow[].

Image
Figure 4.13 Bifurcation diagram of fc. (Brown University Colors)

t2 = Flatten [ t1 , 2 ] ; Image

ListPlot [ t2 , AxesLabel { c , " x c (n), n=100..500 " } , Image

PlotRange { 2 , 2 } , AspectRatio 1 , Image

PlotStyle{CMYKColor[0,1,1,0],PointSize[.005]}]Image □

4.2.1 More on Graphing Lists; Graphing Lists of Points Using Graphics Primitives

Include the Joined->True option in a ListPlot command to connect successive points with line segments or use ListLinePlot.

Using graphics primitives like Point and Line gives you even more flexibility.

Point[{x,y}] represents a point at (x,y)Image.

Line[{{x1,y1},{x2,y2},...,{xn,yn}}]

represents a sequence of points (x1,y1)Image, (x2,y2)Image, …, (xn,yn)Image connected with line segments. A graphics primitive is declared to be a graphics object with Graphics: Show[Graphics[Point[{x,y}]] displays the point (x,y)Image. The advantage of using primitives is that each primitive is affected by the options that directly precede it.

Example 4.16

Table 4.1 shows the percentage of the United States labor force that belonged to unions during certain years. Graph the data represented in the table.

Table 4.1

Union Membership as a Percentage of the Labor Force

Year Union Membership as a Percentage of the Labor Force
1930 11.6
1935 13.2
1940 26.9
1945 35.5
1950 31.5
1955 33.2
1960 31.4
1965 28.4
1970 27.3
1975 25.5
1980 21.9
1985 18.0
1990 16.1

Solution

We begin by entering the data represented in the table as dataunion:

dataunion={{30,11.6},{35,13.2},{40,26.9},{45,35.5},Image

{ 50 , 31.5 } , { 55 , 33.2 } , { 60 , 31.4 } , { 65 , 28.4 } , { 70 , 27.3 } , Image

{ 75 , 25.5 } , { 80 , 21.9 } , { 85 , 18.0 } , { 90 , 16.1 } } ; Image

the x-coordinate of each point corresponds to the year, where x is the number of years past 1900, and the y-coordinate of each point corresponds to the percentage of the United States labor force that belonged to unions in the given year. We then use ListPlot to graph the set of points represented in dataunion in lp1, lp2 (illustrating the PlotStyle option), and lp3 (illustrating the PlotJoined option). All three plots are displayed side-by-side in Fig. 4.14 using Show together with GraphicsRow.

Image
Figure 4.14 Union membership as a percentage of the labor force. (Vanderbilt University colors)

lp1 = ListPlot [ dataunion , PlotLabel “(a)” , Image

PlotStyleBlack];Image

lp2 = ListPlot [ dataunion , Image

PlotStyle { { CMYKColor [ . 3 , . 4 , . 8 , . 15 ] , PointSize [ 0.03 ] } } , Image

PlotLabel “(b)” ] ; Image

lp3 = ListPlot [ dataunion , Joined True , Image

PlotLabel “(c)” , PlotStyle Black ] ; Image

lp4 = ListLinePlot [ dataunion , PlotLabel “(d)” , Image

PlotStyle - > CMYKColor [ . 3 , . 4 , . 8 , . 15 ] ] ; Image

Show [ GraphicsGrid [ { { lp1 , lp2 } , { lp3 , lp4 } } ] ] Image

An alternative to using ListPlot is to use Show, Graphics, and Point to view the data represented in dataunion. In the following command we use Map to apply the function Point to each pair of data in dataunion. The result is not a graphics object and cannot be displayed with Show.

datapts1 = Map [ Point , dataunion ] ; Image

Short [ datapts1 ] Image

{ Point [ { 30 , 11.6 } ] , Point [ { 35 , 13.2 } ] , 9 , Point [ { 85 , 18 . } ] , Point [ { 90 , 16.1 } ] } Image

Next, we use Show and Graphics to declare the set of points Map[Point,dataunion] as graphics objects and name the resulting graphics object dp1. The image is not displayed because a semi-colon is included at the end of the command. The PointSize[.03] command specifies that the points be displayed as filled circles of radius 0.03%Image of the displayed graphics object.

dp1 = Show [ Graphics [ { PointSize [ 0.03 ] , datapts1 } , Image

Axes Automatic ] , PlotLabel “(a)” ] ; Image

The collection of all commands contained within a Graphics command is contained in braces {...}. Each graphics primitive is affected by the options like PointSize, GrayLevel (or RGBColor) directly preceding it. Thus,

datapts2 = ( { GrayLevel [ RandomReal [ ] ] , Point [ # 1 ] } & ) /@ dataunion ; Image

Short [ datapts2 ] Image

dp2 = Show [ Graphics [ { PointSize [ 0.03 ] , datapts2 } , Image

Axes Automatic ] , PlotLabel “(b)” ] ; Image

displays the points in dataunion in various shades of gray in a graphic named dp2 and

datapts3 = ( { PointSize [ RandomReal [ { “0.008” , “0.1” } ] ] , Image

GrayLevel [ RandomReal [ ] ] , Point [ # 1 ] } & ) /@ dataunion ; Image

dp3 = Show [ Graphics [ { datapts3 } , Axes Automatic ] , Image

PlotLabel “(c)” ] ; Image

shows the points in dataunion in various sizes and in various shades of gray in a graphic named dp3. We connect successive points with line segments

connectpts = Graphics [ Line [ dataunion ] ] ; Image

dp4 = Show [ connectpts , dp3 , Axes Automatic , Image

PlotLabel “(d)” ] ; Image

and show all four plots in Fig. 4.15 using Show and GraphicsGrid.

Image
Figure 4.15 Union membership as a percentage of the labor force.

Show[GraphicsGrid[{{dp1,dp2},{dp3,dp4}}]]Image □

With the speed of today's computers and the power of Mathematica, it is relatively easy now to carry out many calculations that required supercomputers and sophisticated programming experience just a few years ago.

Example 4.17

Julia Sets

Plot Julia sets for f(z)=λcoszImage if λ=.66iImage and λ=.665iImage.

Solution

The sets are visualized by plotting the points (a,b)Image for which |fn(a+bi)|Image is not large in magnitude so we begin by forming our complex grid. Using Table and Flatten, we define complexpts to be a list of 62,500 points of the form a+biImage for 250 equally spaced real values of a between 0 and 8 and 300 equally spaced real values of b between −4 and 4 and then f(z)=.66icoszImage.

complexpts = Flatten [ Table [ a + b I , { a , 0 . , 8 . , 8 / 249 } , { b , 4 . , 4 . , 6 / 249 } ] , 1 ] ; Image

Clear [ f ] Image

f [ z _ ] = . 66 I Cos [ z ] Image

( 0 . + 0.66 i ) Cos [ z ] Image

For a given value of c=a+biImage, h(c)Image returns the ordered triple consisting of the real part of c, the imaginary part of c, and the value of f200(c)Image.

h [ c _ ] := { Re [ c ] , Im [ c ] , Nest [ f , c , 200 ] } Image

We then use Map to apply h to complexpts. Observe that Mathematica generates several error messages. When machine precision is exceeded, we obtain an Overflow[] error message; numerical results smaller than machine precision results in an Underflow[] error message. Error messages can be machine specific, so if you don't get any, don't worry. For length considerations, we don't show any that we obtained here.

t1 = Map [ h , complexpts ] // Chop ; Image

We use the error messages to our advantage. In t2, we select those elements of t1 for which the third coordinate is not Indeterminate, which corresponds to the ordered triples (a,b,fn(a+bi))Image for which |fn(a+bi)|Image is not large in magnitude while in t2b, we select those elements of t1 for which the third coordinate is Indeterminate, which corresponds to the ordered triples (a,b,fn(a+bi))Image for which |fn(a+bi)|Image is large in magnitude.

t2 = Select [ t1 , Not [ # [ [ 3 ] ] === Indeterminate ] & ] ; Image

t2b = Select [ t1 , # [ [ 3 ] ] === Indeterminate & ] ; Image

pt [ { x _ , y _ , z _ } ] := { x , y } Image

t3 = Map [ pt , t2 ] ; Image

t3b = Map [ pt , t2b ] ; Image

which are then graphed with ListPlot and shown side-by-side in Fig. 4.16 using Show and GraphicsRow. As expected, the images are inversions of each other.

Image
Figure 4.16 Julia set for 0.66icoszImage. (University of Iowa colors)

lp1 = ListPlot [ t3 , PlotRange { { 0 , 8 } , { 4 , 4 } } , AspectRatio Automatic , Image

PlotStyle CMYKColor [ 0 , . 09 , . 8 , 0 ] , PlotLabel “(a)” ] ; Image

lp2 = ListPlot [ t3b , PlotRange { { 0 , 8 } , { 4 , 4 } } , AspectRatio Automatic , Image

PlotStyleCMYKColor[0,.09,.8,0],PlotLabel“(b)”];Image

Show [ GraphicsRow [ { lp1 , lp2 } ] ] Image

Changing λ from 0.66i to 0.665i results in a surprising difference in the plots. We proceed as before but increase the number of sample points to 120,000. See Fig. 4.17.

We encountered similar error messages are as before but we have not included them due to length considerations.

Image
Figure 4.17 Julia set for 0.665icoszImage.

complexpts = Flatten [ Table [ a + b I , { a , 2 . , 2 . , 4 / 399 } , { b , 0 . , 2 . , 2 / 299 } ] , 1 ] ; Image

Clear [ f ] Image

f [ z _ ] = . 665 I Cos [ z ] ; Image

h [ c _ ] := { Re [ c ] , Im [ c ] , Nest [ f , c , 200 ] } Image

t1 = Map [ h , complexpts ] // Chop ; Image

t2 = Select [ t1 , Not [ # [ [ 3 ] ] === Indeterminate ] & ] ; Image

t2 = Select [ t2 , Not [ # [ [ 3 ] ] === Overflow [ ] ] & ] ; Image

t2b = Select [ t1 , # [ [ 3 ] ] === Indeterminate & ] ; Image

pt [ { x _ , y _ , z _ } ] := { x , y } Image

t3=Map[pt,t2];Image

t3b = Map [ pt , t2b ] ; Image

lp1 = ListPlot [ t3 , PlotRange { { 2 , 2 } , { 0 , 2 } } , AspectRatio Automatic , Image

PlotStyle Black , PlotLabel “(a)” ] ; Image

lp2 = ListPlot [ t3b , PlotRange { { 2 , 2 } , { 0 , 2 } } , AspectRatio Automatic , Image

PlotStyle Black , PlotLabel “(b)” ] ; Image

Show [ GraphicsRow [ { lp1 , lp2 } ] ] Image

To see detail, we take advantage of pure functions, Map, and graphics primitives in three different ways. In Fig. 4.18, the shading of the point (a,b)Image is assigned according to the distance of f200(a+bi)Image from the origin. The color black indicates a distance of zero from the origin; as the distance increases, the shading of the point becomes lighter.

Image
Figure 4.18 Shaded Julia sets for 0.665icoszImage.

t2p = Map [ { # [ [ 1 ] ] , # [ [ 2 ] ] , Min [ Abs [ # [ [ 3 ] ] ] , 3 ] } & , t2 ] ; Image

t2p2 = Map [ { GrayLevel [ # [ [ 3 ] ] / 3 ] , Point [ { # [ [ 1 ] ] , # [ [ 2 ] ] } ] } & , Image

t2p ] ; Image

jp1 = Show [ Graphics [ t2p2 ] , PlotRange { { 2 , 2 } , { 0 , 2 } } , Image

AspectRatio 1 , PlotLabel “(a)” ] ; Image

t2p = Map [ { # [ [ 1 ] ] , # [ [ 2 ] ] , Min [ Abs [ Re [ # [ [ 3 ] ] ] ] , . 25 ] } & , t2 ] ; Image

t2p2 = Map [ { GrayLevel [ # [ [ 3 ] ] / . 25 ] , Point [ { # [ [ 1 ] ] , # [ [ 2 ] ] } ] } & , Image

t2p ] ; Image

jp2 = Show [ Graphics [ t2p2 ] , PlotRange { { 2 , 2 } , { 0 , 2 } } , AspectRatio 1 , Image

PlotLabel “(b)” ] ; Image

t2p = Map [ { # [ [ 1 ] ] , # [ [ 2 ] ] , Min [ Abs [ Im [ # [ [ 3 ] ] ] ] , 2.5 ] } & , t2 ] ; Image

t2p2 = Map [ { GrayLevel [ # [ [ 3 ] ] / 2.5 ] , Point [ { # [ [ 1 ] ] , # [ [ 2 ] ] } ] } & , Image

t2p ] ; Image

jp3 = Show [ Graphics [ t2p2 ] , PlotRange { { 2 , 2 } , { 0 , 2 } } , AspectRatio 1 , Image

PlotLabel“(c)”];Image

Show [ GraphicsRow [ { jp1 , jp2 , jp3 } ] ] Image

Often times the Julia set is only defined for a rational function. With Mathematica, the command JuliaSetPlot[f[z],z] plots the Julia set of the rational function y=f(z)Image. To obtain good results, you will often want to take advantage of options such as PlotRange and PlotStyle. However, by the nature of the computations involved you should view JuliaSetPlot as a “fragile” commmand.

To illustrate approximating a Julia set for f(z)=0.66icoszImage, we first use Series together with Normal to compute the Maclaurin series of degree 24 for f(z)Image. We then use JuliaSetPlot to graph the Julia set for this polynomial in jp1. See Fig. 4.19 (a). Observe that the approximation is fairly close to what we obtained previously.

Image
Figure 4.19 Approximating Julia sets of 0.66icoszImage and 0.665icoszImage.

p1 = Series [ 0.66 I Cos [ z ] , { z , 0 , 24 } ] // Normal Image

( 0 . + 0.66 i ) ( 0 . + 0.33 i ) z 2 + ( 0 . + 0.0275 i ) z 4 ( 0 . + 0.000916667 i ) z 6 + ( 0 . + 0.000016369 i ) z 8 ( 0 . + 1.8187830687830687 ` * 7 i ) z 10 + ( 0 . + 1.3778659611992948 ` * 9 i ) z 12 ( 0 . + 7.570692094501619 ` * 12 i ) z 14 + ( 0 . + 3.1544550393756745 ` * 14 i ) z 16 ( 0 . + 1.0308676599266909 ` * 16 i ) z 18 + ( 0 . + 2.712809631386029 ` * 19 i ) z 20 ( 0 . + 5.871882319017379 ` * 22 i ) z 22 + ( 0 . + 1.0637467969234383 ` * 24 i ) z 24 Image

jp1 = JuliaSetPlot [ p1 , z , PlotRange { { 0 , 8 } , { 4 , 4 } } , Image

AspectRatio 1 , PlotLabel “(a)” ] Image

On the other hand, when we repeat the approximation process for f(z)=0.665icoszImage, in Fig. 4.19 (b), we see that the approximation does not appear to agree as well as the approximation for f(z)=0.66icoszImage.

p2 = Series [ 0.665 I Cos [ z ] , { z , 0 , 24 } ] // Normal Image

( 0 . + 0.665 i ) ( 0 . + 0.3325 i ) z 2 + ( 0 . + 0.0277083 i ) z 4 ( 0 . + 0.000923611 i ) z 6 + ( 0 . + 0.0000164931 i ) z 8 ( 0 . + 1.8325617283950616 ` * 7 i ) z 10 + ( 0 . + 1.3883043396932286 ` * 9 i ) z 12 ( 0 . + 7.628045822490267 ` * 12 i ) z 14 + ( 0 . + 3.1783524260376114 ` * 14 i ) z 16 ( 0 . + 1.038677263410984 ` * 16 i ) z 18 + ( 0 . + 2.73336121950259 ` * 19 i ) z 20 ( 0 . + 5.916366275979632 ` * 22 i ) z 22 + ( 0 . + 1.071854847789188 ` * 24 i ) z 24 Image

jp2 = JuliaSetPlot [ p2 , z , PlotRange { { 2 , 2 } , { 0 , 2 } } , Image

AspectRatio 1 , PlotLabel “(b)” ] Image

Show[GraphicsRow[{jp1,jp2}]]Image □

4.2.2 Miscellaneous List Operations

4.2.2.1 Other List Operations

Some other Mathematica commands used with lists include:

1.  Append[list,element], which appends element to list;

2.  AppendTo[list,element], which appends element to list and names the result list;

3.  Drop[list,n], which returns the list obtained by dropping the first n elements from list;

4.  Drop[list,-n], which returns the list obtained by dropping the last n elements of list;

5.  Drop[list,{n,m}], which returns the list obtained by dropping the nth through mth elements of list;

6.  Drop[list,{n}], which returns the list obtained by dropping the nth element of list;

7.  Prepend[list,element], which prepends element to list; and

8.  PrependTo[list,element], which prepends element to list and names the result list.

4.2.2.2 Alternative Way to Evaluate Lists by Functions

Abbreviations of several of the commands discussed in this section are summarized in the following table.

@@ Apply // (function application) {...} List
/@ Map [[...]] Part

4.3 Other Applications

We now present several other applications that we find interesting and require the manipulation of lists. The examples also illustrate (and combine) many of the techniques that were demonstrated in the earlier chapters.

4.3.1 Approximating Lists with Functions

Another interesting application of lists is that of curve-fitting. The commands

1.  Fit[data,functionset,variables] fits the list of data points data using the functions in functionset by the method of least-squares. The functions in functionset are functions of the variables listed in variables; and

2.  InterpolatingPolynomial[data,x] fits the list of n data points data with an n1Image degree polynomial in the variable x.

Example 4.18

Define datalist to be the list of numbers consisting of 1.14479, 1.5767, 2.68572, 2.5199, 3.58019, 3.84176, 4.09957, 5.09166, 5.98085, 6.49449, and 6.12113. (a) Find a quadratic approximation of the points in datalist. (b) Find a fourth degree polynomial approximation of the points in datalist.

Solution

The approximating function obtained via the least-squares method with Fit is plotted along with the data points in Fig. 4.20. Notice that many of the data points are not very close to the approximating function. A better approximation is obtained using a polynomial of higher degree (4).

Image
Figure 4.20 (a) The graph of a quadratic fit shown with the data points. (b) The graph of a quartic fit shown with the data points. (Appalachian State University colors)

Clear [ datalist ] Image

datalist = { 1.14479 , 1.5767 , 2.68572 , 2.5199 , 3.58019 , 3.84176 , Image

4.09957 , 5.09166 , 5.98085 , 6.49449 , 6.12113 } ; Image

p1 = ListPlot [ datalist , PlotStyle Black ] ; Image

Clear [ y ] Image

y [ x _ ] = Fit [ datalist , { 1 , x , x 2 } , x ] Image

0.508266 + 0.608688 x 0.00519281 x 2 Image

p2 = Plot [ y [ x ] , { x , 1 , 11 } , PlotStyle { { Thickness [ . 02 ] , CMYKColor [ 0 , . 09 , . 8 , 0 ] } } ] ; Image

pa = Show [ p1 , p2 , PlotLabel “(a)” ] ; Image

Clear [ y ] Image

y [ x _ ] = Fit [ datalist , { 1 , x , x 2 , x 3 , x 4 } , x ] Image

0.54133 + 2.02744 x 0.532282 x 2 + 0.0709201 x 3 0.00310985 x 4 Image

p3 = Plot [ y [ x ] , { x , 1 , 11 } , PlotStyle { { Thickness [ . 02 ] , CMYKColor [ 0 , . 09 , . 8 , 0 ] } } ] ; Image

pb = Show [ p1 , p3 , PlotLabel “(b)” ] ; Image

Show [ GraphicsRow [ { pa , pb } ] ] Image

To check its accuracy, the second approximation is graphed simultaneously with the data points in Fig. 4.20 (b).  □

Remember that when a semi-colon is placed at the end of the command the resulting output is not displayed by Mathematica.

Next, consider a list of data points made up of ordered pairs.

Example 4.19

Table 4.2 shows the average percentage of petroleum products imported to the United States for certain years. (a) Graph the points corresponding to the data in the table and connect the consecutive points with line segments. (b) Use InterpolatingPolynomial to find a function that approximates the data in the table. (c) Find a fourth degree polynomial approximation of the data in the table. (d) Find a trigonometric approximation of the data in the table.

Table 4.2

Petroleum Products Imported to the United States for Certain Years

Year Percent Year Percent
1973 34.8105 1983 28.3107
1974 35.381 1984 29.9822
1975 35.8167 1985 27.2542
1976 40.6048 1986 33.407
1977 47.0132 1987 35.4875
1978 42.4577 1988 38.1126
1979 43.1319 1989 41.57
1980 37.3182 1990 42.1533
1981 33.6343 1991 39.5108
1982 28.0988

Image

Solution

We begin by defining data to be the set of ordered pairs represented in the table: the x-coordinate of each point represents the number of years past 1900 and the y-coordinate represents the percentage of petroleum products imported to the United States.

data = { { 73 . , 34.8105 } , { 74 . , 35.381 } , { 75 . , 35.8167 } , Image

{ 76 . , 40.6048 } , { 77 . , 47.0132 } , { 78 . , 42.4577 } , Image

{ 79 . , 43.1319 } , { 80 . , 37.3182 } , { 81 . , 33.6343 } , Image

{ 82 . , 28.0988 } , { 83 . , 28.3107 } , { 84 . , 29.9822 } , Image

{ 85 . , 27.2542 } , { 86 . , 33.407 } , { 87 . , 35.4875 } , Image

{88.,38.1126},{89.,41.57},{90.,42.1533},{91.,39.5108}};Image

We use ListPlot to graph the ordered pairs in data. Note that because the option PlotStyle->PointSize[.03] is included within the ListPlot command, the points are larger than they would normally be. We also use ListPlot with the option PlotJoined->True to graph the set of points data and connect consecutive points with line segments. Then we use Show to display lp1 and lp2 together in Fig. 4.21. Note that in the result, the points are easy to distinguish because of their larger size.

Image
Figure 4.21 The points in Table 4.2 connected by line segments. (Northeastern University colors)

lp1 = ListPlot [ data , PlotStyle { { CMYKColor [ 0 , 1 , . 9 , . 05 ] , PointSize [ 0.03 ] } } ] ; Image

lp2 = ListPlot [ data , Joined True , Image

PlotStyle CMYKColor [ 0 , . 13 , . 3 , . 76 ] ] ; Image

Show [ lp1 , lp2 ] Image

Next, we use InterpolatingPolynomial to find a polynomial approximation, p, of the data in the table. Note that the result is lengthy, so Short is used to display an abbreviated form of p. We then graph p and show the graph of p along with the data in the table for the years corresponding to 1971 to 1993 in Fig. 4.22 (a). Although the interpolating polynomial agrees with the data exactly, the interpolating polynomial oscillates wildly.

Image
Figure 4.22 (a) Even though interpolating polynomials agree with the data exactly, they may have extreme oscillations, even for relatively small data sets. (b) Even though the fit does not agree with the data exactly, the oscillations seen in (a). (c) You can use Fit to approximate data by a variety of functions.

p = InterpolatingPolynomial [ data , x ] ; Image

Short [ p , 3 ] Image

39.5108 + ( 0.261128 + ( 0.111875 + ( 0.0622256 + ( 0.00714494 + ( 0.00224511 + ( 1 ) ( 75 . + x ) ) ( 88 . + x ) ) ( 77 . + x ) ) ( 82 . + x ) ) ( 73 . + x ) ) ( 91 . + x ) Image

plotp = Plot [ p , { x , 71 , 93 } , PlotStyle Black ] ; Image

pa = Show [ plotp , lp1 , PlotRange { 0 , 50 } , Image

PlotLabel “(a)” , AspectRatio 1 ] ; Image

To find a polynomial that approximates the data but does not oscillate wildly, we use Fit. Again, we graph the fit and display the graph of the fit and the data simultaneously. In this case, the fit does not identically agree with the data but does not oscillate wildly as illustrated in Fig. 4.22 (b).

Clear [ p ] Image

p = Fit [ data , { 1 , x , x 2 , x 3 , x 4 } , x ] Image

198884 . + 9597.83 x 173.196 x 2 + 1.38539 x 3 0.00414481 x 4 Image

plotp = Plot [ p , { x , 71 , 93 } , PlotStyle Black ] ; Image

pb = Show [ plotp , lp1 , PlotRange { 0 , 50 } , Image

AxesOrigin { 70 , 0 } , PlotLabel “(b)” , Image

AspectRatio 1 ] Image

In addition to curve-fitting with polynomials, Mathematica can also fit the data with trigonometric functions. In this case, we use Fit to find an approximation of the data of the form p=c1+c2sinx+c3sin(x/2)+c4cosx+c5cos(x/2)Image. As in the previous two cases, we graph the fit and display the graph of the fit and the data simultaneously; the results are shown in Fig. 4.22 (c).

See texts like Abell, Braselton, and Rafter's Statistics with Mathematica [15] for a more sophisticated discussion of curve-fitting and related statistical applications.

Clear [ p ] Image

p = Fit [ data , { 1 , Sin [ x ] , Sin [ x 2 ] , Cos [ x ] , Cos [ x 2 ] } , x ] Image

35.4237 + 4.25768 Cos [ x 2 ] 0.941862 Cos [ x ] + 6.06609 Sin [ x 2 ] + 0.0272062 Sin [ x ] Image

“35.4237” + “4.25768” Cos [ x 2 ] “0.941862” Cos [ x ] + Image

“6.06609” Sin [ x 2 ] + “0.0272062” Sin [ x ] Image

35.4237 + 4.25768 Cos [ x 2 ] 0.941862 Cos [ x ] + 6.06609 Sin [ x 2 ] + 0.0272062 Sin [ x ] Image

plotp = Plot [ p , { x , 71 , 93 } , PlotStyle Black ] ; Image

pc=Show[plotp,lp1,PlotRange{0,50},Image

PlotLabel “(c)” , AspectRatio 1 ] ; Image

Show[GraphicsRow[{pa,pb,pc}]]Image □

4.3.2 Introduction to Fourier Series

Many problems in applied mathematics are solved through the use of Fourier series. Mathematica assists in the computation of these series in several ways. Suppose that y=f(x)Image is defined on p<x<pImage. Then the Fourier series for f(x)Image is

1 2 a 0 + n = 1 ( a n cos n π x p + b n sin n π x p )

where

a 0 = 1 p p p f ( x ) d x a n = 1 p p p f ( x ) cos ( n π x p ) d x n = 1 , 2 b n = 1 p p p f ( x ) sin ( n π x p ) d x n = 1 , 2

The kth term of the Fourier series (4.1) is

a n cos n π x p + b n sin n π x p .

The kth partial sum of the Fourier series (4.1) is

1 2 a 0 + n = 1 k ( a n ( cos n π x p ) + b n sin ( n π x p ) ) .

It is a well-known theorem that if y=f(x)Image is a periodic function with period 2p and f(x)Image is continuous on [p,p]Image except at finitely many points, then at each point x the Fourier series for f(x)Image converges and

1 2 a 0 + n = 1 ( a n cos ( n π x p ) + b n sin ( n π x p ) ) = 1 2 ( lim z x + f ( z ) + lim z x f ( z ) ) .

In fact, if the series n=1(|an|+|bn|)Image converges, then the Fourier series converges uniformly on (,)Image.

In the special case that p=πImage, FourierSeries, FourierCosSeries, and FourierSinSeries can be used to carry out these calculations. If y=f(x)Image is defined on [π,π]Image, FourierSeries[f[x],x,n] finds the first n terms of the Fourier series for f(x)Image, FourierCosSeries[f[x],x,n] finds the first n terms of the Fourier cosine series for f(x)Image (even extension), and FourierSinSeries[f[x],x,n] finds the first n terms of the Fourier sin series for f(x)Image (odd extension).

Example 4.20

Let f(x)={x,1x<01,0x<1f(x2),x1Image. Compute and graph the first few partial sums of the Fourier series for f(x)Image.

We begin by clearing all prior definitions of f. We then define the piecewise function f(x)Image and graph f(x)Image on the interval [1,5]Image in Fig. 4.23.

Image
Figure 4.23 Plot of a few periods of f(x). (University of Delaware colors)

Clear [ f ] Image

f [ x _ ] := 1 /; 0 x < 1 Image

f [ x _ ] := x /; 1 x < 0 Image

f [ x _ ] := f [ x 2 ] /; x 1 Image

graphf = Plot [ f [ x ] , { x , 1 , 5 } , PlotStyle { { CMYKColor [ 1 , . 38 , 0 , . 15 ] , Image

Thickness [ . 01 ] } } ] Image

The Fourier series coefficients are computed with the integral formulas in equation (4.2). Executing the following commands defines p to be 1, a[0] to be an approximation of the integral a0=1pppf(x)dxImage, a[n] to be an approximation of the integral an=1pppf(x)cos(nπxp)dxImage, and b[n] to be an approximation of the integral bn=1pppf(x)sin(nπxp)dxImage.

Clear [ a , b , fs , L ] Image

L = 1 ; Image

a [ 0 ] = NIntegrate [ f [ x ] , { x , L , L } ] 2 L Image

0.75

a [ n _ ] := NIntegrate [ f [ x ] Cos [ n π x L ] , { x , L , L } ] L Image

b [ n _ ] := NIntegrate [ f [ x ] Sin [ n π x L ] , { x , L , L } ] L Image

A table of the coefficients a[i] and b[i] for i=1Image, 2, 3, …, 10 is generated with Table and named coeffs. Several error messages (which are not displayed here for length considerations) are generated because of the discontinuities but the resulting approximations are satisfactory for our purposes. The elements in the first column of the table represent the aiImage's and the second column represents the biImage's. Notice how the elements of the table are extracted using double brackets with coeffs.

coeffs = Table [ { a [ i ] , b [ i ] } , { i , 1 , 10 } ] ; Image

TableForm [ coeffs ] Image

0.202642 0.31831 2.7755575615628914 ` * 17 0.159155 0.0225158 0.106103 1.1796119636642288 ` * 16 0.0795775 0.00810569 0.063662 7.112366251504909 ` * 17 0.0530516 0.00413556 0.0454728 5.117434254131581 ` * 17 0.0397887 0.00250176 0.0353678 5.334274688628682 ` * 17 0.031831 Image

The first element of the list is extracted with coeffs[[1]].

coeffs [ [ 1 ] ] Image

{ 0.202642 , 0.31831 } Image

The first element of the second element of coeffs and the second element of the third element of coeffs are extracted with coeffs[[2,1]] and coeffs[[3,2]], respectively.

coeffs [ [ 2 , 1 ] ] Image

2.7755575615628914 ` * 17 Image

coeffs [ [ 3 , 2 ] ] Image

0.106103

After the coefficients are calculated, the nth partial sum of the Fourier series is obtained with Sum. The kth term of the Fourier series, akcos(kπx)+bksin(kπx)Image, is defined in fs. Hence, the nth partial sum of the series is given by

a 0 + k = 1 n [ a k cos ( k π x ) + b k sin ( k π x ) ] = a [ 0 ] + k = 1 n f s [ k , x ] ,

which is defined in fourier using Sum. We illustrate the use of fourier by finding fourier[2,x] and fourier[3,x].

fs [ k _ , x _ ] := coeffs [ [ k , 1 ] ] Cos [ k π x ] + coeffs [ [ k , 2 ] ] Sin [ k π x ] Image

fourier[n_,x_]:=a[0]+k=1nfs[k,x]Image

fourier [ 2 , x ] Image

0.75 0.202642 Cos [ π x ] 2.7755575615628914 ` * -17 Cos [ 2 π x ] + 0.31831 Sin [ π x ] + 0.159155 Sin [ 2 π x ] Image

fourier [ 3 , x ] Image

0.75 0.202642 Cos [ π x ] 2.7755575615628914 ` * -17 Cos [ 2 π x ] 0.0225158 Cos [ 3 π x ] + 0.31831 Sin [ π x ] + 0.159155 Sin [ 2 π x ] + 0.106103 Sin [ 3 π x ] Image

To see how the Fourier series approximates the periodic function, we plot the function simultaneously with the Fourier approximation for n=2Image and n=5Image. The results are displayed together using GraphicsArray in Fig. 4.24.

Image
Figure 4.24 The first few terms of a Fourier series for a periodic function plotted with the function.

graphtwo = Plot [ fourier [ 2 , x ] , { x , 1 , 5 } , Image

PlotStyle { { Thickness [ . 01 ] , CMYKColor [ 0 , . 09 , . 94 , 0 ] } } ] ; Image

bothtwo = Show [ graphtwo , graphf , PlotLabel “(a)” ] ; Image

graphfive = Plot [ fourier [ 5 , x ] , { x , 1 , 5 } , Image

PlotStyle { { Thickness [ . 01 ] , CMYKColor [ 0 , . 09 , . 94 , 0 ] } } ] ; Image

bothfive = Show [ graphfive , graphf , PlotLabel “(b)” ] ; Image

Show[GraphicsRow[{bothtwo,bothfive}]]Image □

Example 4.21

For the first five terms of the Fourier series, Fourier cosine series, and Fourier sine series for f(x)=xImage on [π,π]Image.

Solution

Here we use FourierSeries, FourierCosSeries, and FourierSinSeries.

Clear [ f ] Image

f[x_]=x;Image

f1 = FourierSeries [ x , x , 5 ] Image

f2 = FourierCosSeries [ x , x , 5 ] Image

f3 = FourierSinSeries [ x , x , 5 ] Image

i e i x i e i x 1 2 i e 2 i x + 1 2 i e 2 i x + 1 3 i e 3 i x 1 3 i e 3 i x 1 4 i e 4 i x + 1 4 i e 4 i x + 1 5 i e 5 i x 1 5 i e 5 i x Image

π 2 4 Cos [ x ] π 4 Cos [ 3 x ] 9 π 4 Cos [ 5 x ] 25 π Image

2 ( Sin [ x ] + 1 2 Sin [ 2 x ] 1 3 Sin [ 3 x ] + 1 4 Sin [ 4 x ] 1 5 Sin [ 5 x ] ) Image

Next, we graph the Fourier approximations with f(x)=xImage in Fig. 4.25. In the figure, observe that the Fourier series is the periodic extension of f(x)Image, the Fourier cosine series is the even periodic extension of f(x)Image, and the Fourier sine series is the odd periodic extension of f(x)Image.

Image
Figure 4.25 Approximating f(x) with its Fourier series: the periodic extension in (a), the even extension in (b), and the odd extension in (c).

q1 = Plot [ x , { x , Pi , Pi } , PlotStyle { { CMYKColor [ 1 , . 38 , 0 , . 15 ] , Image

Thickness [ . 01 ] } } ] Image

p1 = Plot [ f1 , { x , 2 Pi , 2 Pi } , Image

PlotStyle { { Thickness [ . 01 ] , CMYKColor [ 0 , . 09 , . 94 , 0 ] } } ] ; Image

p2 = Plot [ f2 , { x , 2 Pi , 2 Pi } , Image

PlotStyle { { Thickness [ . 01 ] , CMYKColor [ 0 , . 09 , . 94 , 0 ] } } ] ; Image

p3 = Plot [ f3 , { x , 2 Pi , 2 Pi } , Image

PlotStyle { { Thickness [ . 01 ] , CMYKColor [ 0 , . 09 , . 94 , 0 ] } } ] ; Image

Show [ GraphicsRow [ { Show [ p1 , q1 , PlotLabel “(a)” ] , Show [ p2 , q1 , PlotLabel “(b)” ] , Image

Show[p3,q1,PlotLabel“(c)”]}]]Image □

Application: The One-Dimensional Heat Equation

A typical problem in applied mathematics that involves the use of Fourier series is that of the one-dimensional heat equation. The boundary value problem that describes the temperature in a uniform rod with insulated surface is

k 2 u x 2 = u t , 0 < x < a , t > 0 , u ( 0 , t ) = T 0 , t > 0 , u ( a , t ) = T a , t > 0 , and u ( x , 0 ) = f ( x ) , 0 < x < a .

In this case, the rod has “fixed end temperatures” at x=0Image and x=aImage and f(x)Image is the initial temperature distribution. The solution to the problem is

u ( x , t ) = T 0 + 1 a ( T a T 0 ) x v ( x ) + n = 1 b n sin ( λ n x ) e λ n 2 k t ,

where

λ n = n π / a and b n = 2 a 0 a ( f ( x ) v ( x ) ) sin n π x a d x ,

and is obtained through separation of variables techniques. The coefficient bnImage in the solution equation (4.6) is the Fourier series coefficient bnImage of the function f(x)v(x)Image, where v(x)Image is the steady-state temperature.

Example 4.22

Solve {2ux2=ut,0<x<1,t>0,u(0,t)=10,u(1,t)=10,t>0,u(x,0)=10+20sin2πx.Image

Solution

In this case, a=1Image and k=1Image. The fixed end temperatures are T0=Ta=10Image, and the initial heat distribution is f(x)=10+20sin2πxImage. The steady-state temperature is v(x)=10Image. The function f(x)Image is defined and plotted in Fig. 4.26. Also, the steady-state temperature, v(x)Image, and the eigenvalue are defined. Finally, Integrate is used to define a function that will be used to calculate the coefficients of the solution.

Image
Figure 4.26 Graph of f(x)=10+20sin2πxImage. (University of Utah colors)

Clear [ f ] Image

f [ x _ ] := 10 + 20 Sin [ π x ] 2 Image

Plot [ f [ x ] , { x , 0 , 1 } , PlotRange { 0 , 30 } , Image

PlotStyle{{Thickness[.01],CMYKColor[0,1,.79,.2]}}]Image

v [ x _ ] := 10 Image

lambda [ n _ ] := n π 4 Image

b [ n _ ] := b [ n ] = 0 4 ( f [ x ] v [ x ] ) Sin [ n π x 4 ] d x Image

Notice that b[n] is defined using the form b[n_]:=b[n]=... so that Mathematica “remembers” the values of b[n] computed and thus avoids recomputing previously computed values. In the following table, we compute exact and approximate values of b[1],...,b[10].

Table [ { n , b [ n ] , b [ n ] // N } , { n , 1 , 10 } ] // TableForm Image

1 5120 63 π 25.869 2 0 0 . 3 1024 33 π 9.87725 4 0 0 . 5 1024 39 π 8.35767 6 0 0 . 7 1024 21 π 15.5214 8 0 0 . 9 5120 153 π 10.6519 10 0 0 . Image

Let Sm=bmsin(λmx)eλm2tImage. Then, the desired solution, u(x,t)Image, is given by

u ( x , t ) = v ( x ) + m = 1 S m .

Let u(x,t,n)=v(x)+m=1nSmImage. Notice that u(x,t,n)=u(x,t,n1)+SnImage. Consequently, approximations of the solution to the heat equation are obtained recursively taking advantage of Mathematica's ability to compute recursively. The solution is first defined for n=1Image by u[x,t,1]. Subsequent partial sums, u[x,t,n], are obtained by adding the nth term of the series, SnImage, to u[x,t,n-1].

u [ x _ , t _ , 1 ] := v [ x ] + b [ 1 ] Sin [ lambda [ 1 ] x ] Exp [ lambda [ 1 ] 2 t ] Image

u [ x _ , t _ , n _ ] := u [ x , t , n 1 ] + b [ n ] Sin [ lambda [ n ] x ] Exp [ lambda [ n ] 2 t ] Image

By defining the solution in this manner a table can be created that includes the partial sums of the solution. In the following table, we compute the first, fourth, and seventh partial sums of the solution to the problem. (See Fig. 4.27.)

Image
Figure 4.27 Animating the temperature distribution in a uniform rod with insulated surface. (University of Utah colors)

Table[u[x,t,n],{n,1,7,3}]Image

{ 10 + 5120 e π 2 t 16 Sin [ π x 4 ] 63 π , 10 + 5120 e π 2 t 16 Sin [ π x 4 ] 63 π + 1024 e 9 π 2 t 16 Sin [ 3 π x 4 ] 33 π , 10 + 5120 e π 2 t 16 Sin [ π x 4 ] 63 π + 1024 e 9 π 2 t 16 Sin [ 3 π x 4 ] 33 π + 1024 e 25 π 2 t 16 Sin [ 5 π x 4 ] 39 π + 1024 e 49 π 2 t 16 Sin [ 7 π x 4 ] 21 π } Image

To generate graphics that can be animated, we use Animate. The 10th partial sum of the solution is plotted for t=0Image to t=1Image.

Animate [ Plot [ u [ x , t , 10 ] , { x , 0 , 1 } , Image

PlotRange { 0 , 60 } , PlotStyle { { Thickness [ . 01 ] , CMYKColor [ 0 , 1 , . 79 , . 2 ] } } ] , Image

{ t , 0 , 1 } ] Image

Alternatively, we may generate several graphics and display the resulting set of graphics as a GraphicsArray. We plot the 10th partial sum of the solution for t=0Image to t=1Image using a step-size of 1/15. The resulting 16 graphs are named graphs which are then partitioned into four element subsets with Partition and named toshow. We then use Show and GraphicsGrid to display toshow in Fig. 4.28.

Image
Figure 4.28 Temperature distribution in a uniform rod with insulated surface.

graphs = Table [ Plot [ Evaluate [ u [ x , t , 10 ] ] , { x , 0 , 1 } , Ticks None , PlotRange { 0 , 60 } , Image

PlotStyle { { Thickness [ . 01 ] , CMYKColor [ 0 , 1 , . 79 , . 2 ] } } ] , { t , 0 , 1 , 1 15 } ] ; Image

toshow = Partition [ graphs , 4 ] ; Image

Show[GraphicsGrid[toshow]]Image □

Fourier series and generalized Fourier series arise in too many applications to list. Examples using them illustrate Mathematica's power to manipulate lists, symbolics, and graphics.

Application: The Wave Equation on a Circular Plate

The vibrations of a circular plate satisfy the equation

D 4 w ( r , θ , t ) + ρ h 2 w ( r , θ , t ) t 2 = q ( r , θ , t ) ,

where 4w=22wImage and 2Image is the Laplacian in polar coordinates, which is defined by

2 = 1 r r ( r r ) + 1 r 2 2 θ 2 = 2 r 2 + 1 r r + 1 r 2 2 θ 2 .

Assuming no forcing so that q(r,θ,t)=0Image and w(r,θ,t)=W(r,θ)eiωtImage, equation (4.7) can be written as

4 W ( r , θ ) β 4 W ( r , θ ) = 0 , β 4 = ω 2 ρ h / D .

For a clamped plate, the boundary conditions are W(a,θ)=W(a,θ)/r=0Image and after much work (see [7]) the normal modes are found to be

W n m ( r , θ ) = [ J n ( β n m r ) J n ( β n m a ) I n ( β n m a ) I n ( β n m r ) ] ( sin n θ cos n θ ) .

In equation (4.9), βnm=λnm/aImage where λnmImage is the mth solution of

I n ( x ) J n ( x ) J n ( x ) I n ( x ) = 0 ,

where Jn(x)Image is the Bessel function of the first kind of order n and In(x)Image is the modified Bessel function of the first kind of order n, related to Jn(x)Image by inIn(x)=Jn(ix)Image.

The Mathematica command BesselI[n,x] returns In(x)Image.

Example 4.23

Graph the first few normal modes of the clamped circular plate.

Solution

We must determine the value of λnmImage for several values of n and m so we begin by defining eqn[n][x] to be In(x)Jn(x)Jn(x)In(x)Image. The mth solution of equation (4.10) corresponds to the mth zero of the graph of eqn[n][x] so we graph eqn[n][x] for n=0Image, 1, 2, and 3 with Plot in Fig. 4.29.

Image
Figure 4.29 Plot of In(x)Jn(x)Jn(x)In(x)Image for n = 0 and 1 in the first row; n = 2 and 3 in the second row.

eqn [ n _ ] [ x _ ] := BesselI [ n , x ] D [ BesselJ [ n , x ] , x ] BesselJ [ n , x ] D [ BesselI [ n , x ] , x ] Image

The result of the Table and Plot command is a list of length four, which is verified with Length[p1].

p1 = Table [ Plot [ Evaluate [ eqn [ n ] [ x ] ] , { x , 0 , 25 } , PlotRange { 10 , 10 } , Image

PlotStyle RGBColor [ . 3 , 3.6 , 7.7 ] ] , { n , 0 , 3 } ] ; Image

so we use Partition to create a 2×2Image array of graphics which is displayed using Show and GraphicsGrid.

p2 = Show [ GraphicsGrid [ Partition [ p1 , 2 ] ] ] Image

To determine λnmImage we use FindRoot. Recall that to use FindRoot to solve an equation an initial approximation of the solution must be given. For example,

l01 = FindRoot [ eqn [ 0 ] [ x ] = = 0 , { x , 3.04 } ] Image

{ x 3.19622 } Image

approximates λ01Image, the first solution of equation (4.10) if n=0Image. However, the result of FindRoot is a list. The specific value of the solution is the second part of the first part of the list, l01, extracted from the list with Part ([[...]]).

l01 [ [ 1 , 2 ] ] Image

3.19622

Thus,

We use the graphs in Fig. 4.29 to obtain initial approximations of each solution.

λ 0s = Map [ FindRoot [ eqn [ 0 ] [ x ] = = 0 , { x , # } ] [ [ 1 , 2 ] ] & , { 3.04 , 6.2 , 9.36 , 12.5 , 15.7 } ] Image

{3.19622,6.30644,9.4395,12.5771,15.7164}Image

approximates the first five solutions of equation (4.10) if n=0Image and then returns the specific value of each solution. We use the same steps to approximate the first five solutions of equation (4.10) if n=1Image, 2, and 3.

λ 1s = Map [ FindRoot [ eqn [ 1 ] [ x ] = = 0 , { x , # } ] [ [ 1 , 2 ] ] & , { 4.59 , 7.75 , 10.9 , 14.1 , 17.2 } ] Image

{ 4.6109 , 7.79927 , 10.9581 , 14.1086 , 17.2557 } Image

λ 2s = Map [ FindRoot [ eqn [ 2 ] [ x ] = = 0 , { x , # } ] [ [ 1 , 2 ] ] & , { 5.78 , 9.19 , 12.4 , 15.5 , 18.7 } ] Image

{ 5.90568 , 9.19688 , 12.4022 , 15.5795 , 18.744 } Image

λ 3s = Map [ FindRoot [ eqn [ 3 ] [ x ] = = 0 , { x , # } ] [ [ 1 , 2 ] ] & , { 7.14 , 10.5 , 13.8 , 17 , 20.2 } ] Image

{ 7.14353 , 10.5367 , 13.7951 , 17.0053 , 20.1923 } Image

All four lists are combined together in λs.

λ s = { λ 0s , λ 1s , λ 2s , λ 3s } ; Image

Short [ λ s ] Image

1 Image

For n=0Image, 1, 2, and 3 and m=1Image, 2, 3, 4, and 5, λnmImage is the mth part of the (n+1)Imagest part of λs.

Observe that the value of a does not affect the shape of the graphs of the normal modes so we use a=1Image and then define βnmImage.

a = 1 ; Image

β [ n _ , m _ ] := λ s [ [ n + 1 , m ] ] / a Image

ws is defined to be the sine part of equation (4.9)

ws [ n _ , m _ ] [ r _ , θ _ ] := Image

( BesselJ [ n , β [ n , m ] r ] BesselJ [ n , β [ n , m ] a ] / BesselI [ n , β [ n , m ] a ] BesselI [ n , β [ n , m ] r ] ) Image

Sin [ n θ ] Image

and wc to be the cosine part.

wc [ n _ , m _ ] [ r _ , θ _ ] := Image

( BesselJ [ n , β [ n , m ] r ] BesselJ [ n , β [ n , m ] a ] / BesselI [ n , β [ n , m ] a ] BesselI [ n , β [ n , m ] r ] ) Image

Cos [ n θ ] Image

We use ParametricPlot3D to plot ws and wc. For example,

ParametricPlot3D [ { r Cos [ θ ] , r Sin [ θ ] , ws [ 3 , 4 ] [ r , θ ] } , { r , 0 , 1 } , { θ , Pi , Pi } , Image

PlotPoints 60 , PlotStyle Opacity [ . 5 , RGBColor [ 2.21 , . 85 , . 12 ] ] ] Image

graphs the sine part of W34(r,θ)Image shown in Fig. 4.30.

Image
Figure 4.30 The sine part of W34(r,θ). (Auburn University colors)

We use Table together with ParametricPlot3D followed by Show and GraphicsGrid to graph the sine part of Wnm(r,θ)Image for n=0Image, 1, 2, and 3 and m=1Image, 2, 3, and 4 shown in Fig. 4.31.

Image
Figure 4.31 The sine part of Wnm(r,θ): n = 0 in row 1, n = 1 in row 2, n = 2 in row 3, and n = 3 in row 4 (m = 1 to 4 from left to right in each row).

ms = Table [ ParametricPlot3D [ { r Cos [ θ ] , r Sin [ θ ] , ws [ n , m ] [ r , θ ] } , { r , 0 , 1 } , Image

{ θ , Pi , Pi } , PlotStyle Opacity [ . 5 , RGBColor [ 3 , 36 , 77 ] ] , Image

PlotPoints 30 , BoxRatios { 1 , 1 , 1 } ] , { n , 0 , 3 } , { m , 1 , 4 } ] ; Image

Show [ GraphicsGrid [ ms ] ] Image

Identical steps are followed to graph the cosine part shown in Fig. 4.32.

Image
Figure 4.32 The cosine part of Wnm(r,θ): n = 0 in row 1, n = 1 in row 2, n = 2 in row 3, and n = 3 in row 4 (m = 1 to 4 from left to right in each row).

mc = Table [ ParametricPlot3D [ { r Cos [ θ ] , r Sin [ θ ] , wc [ n , m ] [ r , θ ] } , { r , 0 , 1 } , Image

{ θ , Pi , Pi } , PlotStyle Opacity [ . 5 , RGBColor [ 3 , 36 , 77 ] ] , Image

PlotPoints 30 , BoxRatios { 1 , 1 , 1 } ] , { n , 0 , 3 } , { m , 1 , 4 } ] ; Image

Show[GraphicsGrid[mc]]Image □

4.3.3 The Mandelbrot Set and Julia Sets

In Examples 4.9, 4.15, and 4.17 we illustrated several techniques for plotting bifurcation diagrams and Julia sets. For investigating Julia sets, try using built-in commands like JuliaSetPlot first. Similarly, for investigating the Mandelbrot set, try MandelbrotSetPlot along with its many options to see if you can obtain your desired results before spending a lot of time writing your own code.

See references like Barnsley's Fractals Everywhere [3] or Feldman's Chaos and Fractals [6] for detailed discussions regarding many of the topics briefly described in this section.

Let fc(x)=x2+cImage. In Example 4.15, we generated the c-values when plotting the bifurcation diagram of fcImage. Depending upon how you think and approach various problems, some approaches may be easier to understand than others. With the exception of very serious calculations, the differences in the time needed to carry out the computations may be minimal so we encourage you to follow the approach that you understand.

fc(x)=x2+cImage is the special case of p=2Image for fp,c(x)=xp+cImage.

Example 4.24

Dynamical Systems

For example, entering

Compare the approach here with the approach used in Example 4.15.

Clear [ f , h ] Image

f[c_][x_]:=x2+c//N;Image

defines fc(x)=x2+cImage so

Nest [ f [ 1 ] , x , 3 ] Image

1 . + ( 1 . + ( 1 . + x 2 ) 2 ) 2 Image

computes f13(x)=(f1f1f1)(x)Image and

Table [ Nest [ f [ 1 / 4 ] , 0 , n ] , { n , 101 , 200 } ] // Short Image

{ 0.490693 , 0.490779 , 96 , 0.495148 , 0.495171 } Image

returns a list of f1/4n(0)Image for n=101Image, 102, …, 200. Thus,

lgtable = Table [ { c , Nest [ f [ c ] , 0 , n ] } , Image

{ c , 2 , 1 / 4 , 9 / ( 4 299 ) } , { n , 101 , 200 } ] ; Image

Length [ lgtable ] Image

300

returns a list of lists of fcn(0)Image for n=101Image, 102, …, 200 for 300 equally spaced values of c between −2 and 1. The list lgtable is converted to a list of points with Flatten and plotted with ListPlot. See Fig. 4.33 and compare this result to the result obtained in Example 4.15.

Image
Figure 4.33 Another bifurcation diagram for fc.

toplot = Flatten [ lgtable , 1 ] ; Image

ListPlot [ toplot , Image

PlotStyle CMYKColor [ 1 , . 69 , . 07 , . 3 ] ] Image

For a given complex number c the Julia set, JcImage, of fc(x)=x2+cImage is the set of complex numbers, z=a+biImage, a,bImage real, for which the sequence z, fc(z)=z2+cImage, fc(fc(z))=(z2+c)2+cImage, …, fcn(z)Image, …, does not tend to ∞ as nImage:

J c = { z C | z , z 2 + c ( z 2 + c ) 2 + c , } .

Using a dynamical system, setting z=z0Image and computing zn+1=fc(zn)Image for large n can help us determine if z is an element of JcImage. In terms of a composition, computing fcn(z)Image for large n can help us determine if z is an element of JcImage.

We use the notation fn(x)Image to represent the composition (fff)n(x)Image.

Example 4.25

Julia Sets

Plot the Julia set of fc(x)=x2+cImage if c=0.122561+0.744862iImage.

As with previous examples, all error messages have been deleted.

Solution

After defining fc(x)=x2+cImage, we use Table together with Nest to compute ordered triples of the form (x,y,f0.122561+0.744862i200(x+iy))Image for 150 equally spaced values of x between 3/2Image and 3/2 and 150 equally spaced values of y between 3/2Image and 3/2.

You do not need to redefine fc(x)Image if you have already defined it during your current Mathematica session.

Clear [ f , h ] Image

f [ c _ ] [ x _ ] := x 2 + c // N ; Image

g1 = Table [ { x , y , Nest [ f [ 0.12256117 + . 74486177 I ] , x + I y , 200 ] } , Image

{ x , 3 / 2 , 3 / 2 , 3 / 149 } , { y , 3 / 2 , 3 / 2 , 3 / 149 } ] ; Image

g2 = Flatten [ g1 , 1 ] ; Image

Take [ g2 , 5 ] Image

{ { 3 2 , 3 2 , Overflow [ ] } , { 3 2 , 441 298 , Overflow [ ] } , { 3 2 , 435 298 , Overflow [ ] } , { 3 2 , 429 298 , Overflow [ ] } , { 3 2 , 423 298 , Overflow [ ] } } Image

We remove those elements of g2 for which the third coordinate is Overflow[] with Select,

g3 = Select [ g2 , Not [ # [ [ 3 ] ] === Overflow [ ] ] & ] ; Image

extract a list of the first two coordinates, (x,y)Image, from the elements of g3,

g4 = Map [ { # [ [ 1 ] ] , # [ [ 2 ] ] } & , g3 ] ; Image

and plot the resulting list of points in Fig. 4.34 using ListPlot.

Image
Figure 4.34 Filled Julia set for fc.

lp1 = ListPlot [ g4 , PlotRange { { 3 / 2 , 3 / 2 } , { 3 / 2 , 3 / 2 } } , Image

AxesLabel { x , y } , AspectRatio Automatic , Image

PlotStyle CMYKColor [ 0 , . 12 , . 98 , 0 ] ] Image

We can invert the image as well with the following commands. In the end result, we show the Julia set and its inverted image in Fig. 4.35

Image
Figure 4.35 Filled Julia set for fc on the left; the inverted set on the right.

g3b = Select [ g2 , # [ [ 3 ] ] === Overflow [ ] & ] ; Image

g4b = Map [ { # [ [ 1 ] ] , # [ [ 2 ] ] } & , g3b ] ; Image

lp2 = ListPlot [ g4b , PlotRange { { 3 / 2 , 3 / 2 } , { 3 / 2 , 3 / 2 } } , AxesLabel { x , y } , Image

AspectRatio Automatic , PlotStyle CMYKColor [ 0 , . 12 , . 98 , 0 ] ] ; Image

j1 = Show [ GraphicsRow [ { lp1 , lp2 } ] ] Image

For rational functions f(z)Image you can use the command JuliaSetPlot[f[z],z] to plot the Julia set for f(z)Image. The default is f(z)=z2+cImage so JuliaSetPlot[c] plots the Julia set for f(z)=z2+cImage. Use options like PlotRange to get the view of the plot that you expect.

Thus, in the following commands, all plot the Julia set for f(z)=z2+cImage for c=0.12256117+.74486177iImage.

jsp1 = JuliaSetPlot [ f [ 0.12256117 + . 74486177 I ] [ x ] , x , PlotRange Image

{ { 3 / 2 , 3 / 2 } , { 3 / 2 , 3 / 2 } } ] Image

jsp2 = JuliaSetPlot [ f [ 0.12256117 + . 74486177 I ] [ x ] , x , PlotStyle Image

CMYKColor [ 0 , . 12 , . 98 , 0 ] , Image

PlotRange { { 3 / 2 , 3 / 2 } , { 3 / 2 , 3 / 2 } } ] Image

jsp3 = JuliaSetPlot [ 0.12256117 + . 74486177 I , PlotStyle CMYKColor [ 1 , . 69 , . 07 , . 3 ] , Image

PlotRange { { 3 / 2 , 3 / 2 } , { 3 / 2 , 3 / 2 } } ] Image

The plots are all shown together in Fig. 4.36.

Image
Figure 4.36 Various views of the Julia set for f(z)=z2 + c if c = −0.12256117 + .74486177i.

Show[GraphicsRow[{jsp1,jsp2,jsp3}]]Image □

Of course, one can consider functions other than fc(x)=x2+cImage as well as rearrange the order in which we carry out the computations.

Example 4.26

Julia Sets

Plot the Julia set for fc(z)=z2czImage if c=0.737369+0.67549iImage.

As before, all error messages have been deleted.

Solution

Observe that fc(z)=z2czImage is a true rational function (it is a polynomial) so JuliaSetPlot will plot the Julia set.

After defining fc(z)=z2czImage,

Clear [ f , h ] Image

f [ c _ ] [ x _ ] := x 2 c x // N ; Image

we use JuliaSetPlot as in the previous example. See Fig. 4.37.

Image
Figure 4.37 The Julia set for f0.737369+0.67549i200(z)Image.

JuliaSetPlot [ f [ 0.737369 + 0.67549 I ] [ x ] , x , PlotRange { { 3 / 2 , 3 / 2 } , { 3 / 2 , 3 / 2 } } , Image

PlotStyle CMYKColor [ 0 , . 24 , . 94 , 0 ] ] Image

You can use commands like Table and Manipulate to investigate the Julia set for Jc(x)Image. For example,

t1=Table[JuliaSetPlot[f[0.737369k+0.67549I][x],x,Image

PlotRange { { 3 / 2 , 3 / 2 } , { 3 / 2 , 3 / 2 } } , Image

PlotStyle CMYKColor [ 0 , . 24 , . 94 , 0 ] ] , { k , . 5 , 1.5 , 1 / 8 } ] ; Image

plots the Julia set for f0.737369k+0.67549i(x)Image for 9 equally spaced values of k between .5 and 1.5. The results are shown as an array with GraphicsGrid in Fig. 4.38. □

Image
Figure 4.38 The Julia set for f0.737369k+0.67549i(x) for 9 equally spaced values of k between .5 and 1.5.

Example 4.27

The Ikeda Map

The Ikeda map is defined by

F ( x , y ) = γ + β ( x cos τ y sin τ ) , β ( x sin τ + y cos τ ) ,

where τ=μα/(1+x2+y2)Image. If β=.9Image, μ=.4Image, and α=4.0Image, plot the basins of attraction for F if γ=.92Image and γ=1.0Image.

Solution

The basins of attraction for F are the set of points (x,y)Image for which Fn(x,y)Image as nImage.

After defining f[γ][x,y]Image to be equation (4.11) and then β=.9Image, μ=.4Image, and α=4.0Image, we use Table followed by Flatten to define pts to be the list of 40,000 ordered pairs (x,y)Image for 200 equally spaced values of x between −2.3 and 1.3 and 200 equally spaced values of y between −2.8 and .8.

f [ γ _ ] [ { x _ , y _ } ] := Image

{ γ + β ( x Cos [ μ α / ( 1 + x 2 + y 2 ) ] y Sin [ μ α / ( 1 + x 2 + y 2 ) ] ) , Image

β ( x Sin [ μ α / ( 1 + x 2 + y 2 ) ] + y Cos [ μ α / ( 1 + x 2 + y 2 ) ] ) } Image

β = . 9 ; μ = . 4 ; α = 4.0 ; Image

pts = Flatten [ Table [ { x , y } , { x , 2.3 , 1.3 , 3.6 / 199 } , { y , 2.8 , . 8 , 3.6 / 199 } ] , Image

1 ] ; Image

In l1, we use Map to compute (x,y,F.92200(x,y))Image for each (x,y)Image in pts. In pts2, we use the graphics primitive Point and shade the points according to the maximum value of F200(x,y)Image – those (x,y)Image for which F200(x,y)Image is closest to the origin are darkest; the point (x,y)Image is shaded lighter as the distance of F200(x,y)Image from the origin increases. (See Fig. 4.39 (a).)

Image
Figure 4.39 Basins of attraction for F if γ = .92 (a) and γ = 1.0 (b).

l1 = Map [ { # [ [ 1 ] ] , # [ [ 2 ] ] , Nest [ f [ . 92 ] , { # [ [ 1 ] ] , # [ [ 2 ] ] } , 200 ] } & , pts ] ; Image

g [ { x _ , y _ , z _ } ] := { x , y , Sqrt [ z [ [ 1 ] ] 2 + z [ [ 2 ] ] 2 ] } ; Image

l2 = Map [ g , l1 ] ; Image

maxl2 = Table [ l2 [ [ i , 3 ] ] , { i , 1 , Length [ l2 ] } ] // Max Image

4.33321

pts2 = Table [ { GrayLevel [ l2 [ [ i , 3 ] ] / ( maxl2 ) ] , Image

Point [ { l2 [ [ i , 1 ] ] , l2 [ [ i , 2 ] ] } ] } , { i , 1 , Length [ l2 ] } ] ; Image

ik1 = Show [ Graphics [ pts2 ] , AspectRatio 1 ] Image

For γ=1.0Image, we proceed in the same way. The final results are shown in Fig. 4.39 (b).

l1 = Map [ { # [ [ 1 ] ] , # [ [ 2 ] ] , Nest [ f [ 1.0 ] , { # [ [ 1 ] ] , # [ [ 2 ] ] } , 200 ] } & , pts ] ; Image

l2 = Map [ g , l1 ] ; Image

maxl2 = Table [ l2 [ [ i , 3 ] ] , { i , 1 , Length [ l2 ] } ] // Max Image

4.48421

pts2 = Table [ { GrayLevel [ l2 [ [ i , 3 ] ] / maxl2 ] , Point [ { l2 [ [ i , 1 ] ] , l2 [ [ i , 2 ] ] } ] } , Image

{ i , 1 , Length [ l2 ] } ] ; Image

ik2 = Show [ Graphics [ pts2 ] , AspectRatio 1 ] Image

Show[GraphicsRow[{ik1,ik2}]]Image □

The Mandelbrot set, M, is the set of complex numbers, z=a+biImage, a,bImage real, for which the sequence z, fz(z)=z2+zImage, fz(fz(z))=(z2+z)2+zImage, …, fzn(z)Image, …, does not tend to ∞ as nImage:

M = { z C | z , z 2 + z ( z 2 + z ) 2 + z , } .

Using a dynamical system, setting z=z0Image and computing zn+1=fz0(zn)Image for large n can help us determine if z is an element of M. In terms of a composition, computing fzn(z)Image for large n can help us determine if z is an element of M.

The command

 MandelbrotSetPlot[{a+bi,c+di}] 

plots the Mandelbrot set on the rectangle with lower left corner a+biImage and upper right corner c+diImage.

Example 4.28

Mandelbrot Set

Plot the Mandelbrot set.

Solution

We use MandelbrotSetPlot. The following gives us the image on the left in Fig. 4.40.

Image
Figure 4.40 The Mandelbrot set.

MandelbrotSetPlot[{3/2I,1+I}]Image □

The Mandelbrot set can be obtained (or more precisely, approximated) by repeatedly composing fz(z)Image for a grid of z-values and then deleting those for which the values exceed machine precision or other specified “large” value. Those values greater than $MaxNumber result in an Overflow[] message; computations with Overflow[] result in an Indeterminate message.

We can generalize by considering exponents other than 2 by letting fp,c=xp+cImage. The generalized Mandelbrot set, MpImage, is the set of complex numbers, z=a+biImage, a,bImage real, for which the sequence z, fp,z(z)=zp+zImage, fp,z(fp,z(z))=(zp+z)p+zImage, …, fp,zn(z)Image, …, does not tend to ∞ as nImage:

M p = { z C | z , z p + z ( z p + z ) p + z , } .

Using a dynamical system, setting z=z0Image and computing zn+1=fp(zn)Image for large n can help us determine if z is an element of MpImage. In terms of a composition, computing fpn(z)Image for large n can help us determine if z is an element of MpImage.

Example 4.29

Generalized Mandelbrot Set

As with the previous examples, all error messages have been omitted.

After defining fp,c=xp+cImage, we use Table, Abs, and Nest to compute a list of ordered triples of the form (x,y,|fp,x+iy100(x+iy)|)Image for p-values from 1.625 to 2.625 spaced by equal values of 1/8 and 200 values of x (y) values equally spaced between −2 and 2, resulting in 40,000 sample points of the form x+iyImage.

Clear [ f , p ] Image

f [ p _ , c _ ] [ x _ ] := x p + c // N ; Image

g1 = Image

Map [ Table [ { x , y , Abs [ Nest [ f [ 2 , x + I y ] , x + I y , # ] ] } // N , { x , 1.5 , 1 . , 5 / ( 2 199 ) } , Image

{ y , 1 . , 1 . , 2 / 199 } ] & , { 5 , 10 , 15 , 25 , 50 , 100 } ] ; Image

g2 = Map [ Flatten [ # , 1 ] & , g1 ] ; Image

Next, we extract those points for which the third coordinate is Indeterminate with Select, ordered pairs of the first two coordinates are obtained in g4. The resulting list of points is plotted with ListPlot in Fig. 4.41.

Image
Figure 4.41 The generalized Mandelbrot set for 9 equally spaced values of p between 1.625 and 2.625.

g3 = Table [ Select [ g2 [ [ i ] ] , Not [ # [ [ 3 ] ] === Overflow [ ] ] & ] , { i , 1 , Length [ g2 ] } ] ; Image

h [ { x _ , y _ , z _ } ] := { x , y } ; Image

g4=Map[h,g3,{2}];Image

t1 = Table [ ListPlot [ g4 [ [ i ] ] , PlotRange { { 3 2 , 1 } , { 1 , 1 } } , Image

AspectRatio Automatic , DisplayFunction Identity ] , { i , 1 , 6 } ] ; Image

Show [ GraphicsGrid [ Partition [ t1 , 3 ] ] ] Image

More detail is observed if you use the graphics primitive Point as shown in Fig. 4.42. In this case, those points (x,y)Image for which |fp,x+iy100(x+iy)|Image is small are shaded according to a darker GrayLevel than those points for which |fp,x+iy100(x+iy)|Image is large.

Image
Figure 4.42 The generalized Mandelbrot set for 9 equally spaced values of p between 1.625 and 2.625 – the points (x,y) for which |fp,x+iy100(x+iy)|Image is large are shaded lighter than those for which |fp,x+iy100(x+iy)|Image is small.

h2 [ { x _ , y _ , z _ } ] := { GrayLevel [ Min [ { z , 1 } ] ] , Point [ { x , y } ] } ; Image

g5 = Map [ h2 , g3 , { 2 } ] ; Image

t1 = Table [ Show [ Graphics [ g5 [ [ i ] ] ] , PlotRange { { 3 2 , 1 } , { 1 , 1 } } , Image

AspectRatio Automatic , DisplayFunction Identity ] , { i , 1 , 6 } ] ; Image

Show [ GraphicsGrid [ Partition [ t1 , 3 ] ] ] Image

Throughout these examples, we have typically computed the iteration fn(z)Image for “large” n like values of n between 100 and 200. To indicate why we have selected those values of n, we revisit the Mandelbrot set plotted in Example 4.28.

Example 4.30

Mandelbrot Set

We proceed in essentially the same way as in the previous examples. After defining fp,c=xp+cImage,

As before, all error messages have been deleted.

Clear [ f , p ] Image

f [ p _ , c _ ] [ x _ ] := x p + c // N ; Image

we use Table followed by Map to create a nested list. For each n=5Image, 10, 15, 25, 50, and 100, a nested list is formed for 200 equally spaced values of y between −1 and 1 and then 200 equally spaced values of x between −1.5 and 1. between −1.5 and 1. At the bottom level of each nested list, the elements are of the form (x,y,|f2,x+iyn(x+iy)|)Image.

g1 = Table [ { x , y , Abs [ Nest [ f [ p , x + I y ] , x + I y , 100 ] ] } // N , Image

{ p , 1.625 , 2.625 , 1 / 8 } , { x , 2 . , 2 . , 4 / 149 } , { y , 2 . , 2 . , 4 / 149 } ] ; Image

pvals = Table [ p , { p , 1.625 , 2.625 , 1 / 5 } ] ; Image

g1=Map[Table[{x,y,Abs[Nest[f[#,x+Iy],x+Iy,100]]}//N,Image

{ x , 1.5 , 1 . , 5 / ( 2 199 ) } , { y , 1 . , 1 . , 2 / 199 } ] & , pvals ] ; Image

For each value of n, the corresponding list of ordered triples (x,y,|f2,x+iyn(x+iy)|)Image is obtained using Flatten.

g2 = Map [ Flatten [ # , 1 ] & , g1 ] ; Image

We then remove those points for which the third coordinate, |f2,x+iyn(x+iy)|Image, is Overflow[] (corresponding to ∞),

g3 = Table [ Select [ g2 [ [ i ] ] , Not [ # [ [ 3 ] ] === Indeterminate ] & ] , Image

{ i , 1 , Length [ g2 ] } ] ; Image

extract (x,y)Image from the remaining ordered triples,

h [ { x _ , y _ , z _ } ] := { x , y } ; Image

g4 = Map [ h , g3 , { 2 } ] ; Image

and graph the resulting sets of points using ListPlot in Fig. 4.43. As shown in Fig. 4.43, we see that Mathematica's numerical precision (and consequently decent plots) are obtained when n=50Image or n=100Image.

Image
Figure 4.43 Without shading the points, the effects of iteration are difficult to see until the number of iterations is “large”.

Fundamentally, we generated the previous plots by exceeding Mathematica's numerical precision.

t1 = Table [ ListPlot [ g4 [ [ i ] ] , PlotRange { { 2 , 2 } , { 2 , 2 } } , Image

AspectRatio Automatic , DisplayFunction Identity ] , { i , 1 , 9 } ] ; Image

Show [ GraphicsGrid [ Partition [ t1 , 3 ] ] ] Image

If instead, we use graphics primitives like Point and then shade each point (x,y)Image according to |f2,x+iyn(x+iy)|Image detail emerges quickly as shown in Fig. 4.44.

Image
Figure 4.44 Using graphics primitives and shading, we see that we can use a relatively small number of iterations to visualize the Mandelbrot set.

h2 [ { x _ , y _ , z _ } ] := { GrayLevel [ Min [ { z , . 25 } ] ] , Point [ { x , y } ] } ; Image

g5 = Map [ h2 , g3 , { 2 } ] ; Image

t1 = Table [ Show [ Graphics [ g5 [ [ i ] ] ] , PlotRange { { 2 , 2 } , { 2 , 2 } } , Image

AspectRatio Automatic , DisplayFunction Identity ] , { i , 1 , 9 } ] ; Image

Show [ GraphicsGrid [ Partition [ t1 , 3 ] ] ] Image

The examples like the ones illustrated here indicate that similar results could have been accomplished using far smaller values of n than n=100Image or n=200Image. With fast machines, the differences in the time needed to perform the calculations is minimal; n=100Image and n=200Image appear to be a “safe” large value of n for well-studied examples like these.