Lecture 07

Lecture 07
(with solutions)
Summer 2001
Victor Adamchik
Off#General::spell'; Off#General::spell1'; $Line
0;
Exercise 1
Vieta's formula, developed in 1593, expresses ccccS2 as an infinite product of nested square roots.
\
L
]
M 1 '(((((((((((((((((((((((((((((
%&&&&&&&&&&&&&&&&
r$$$$ ]
r$$$$ M
2
1 r$$$$
1 %&&&&&&&&&&&&&&&&
]
M
.
.
.
]
#…
ccc
m
,
ccc
#
ccc
#
1#
M
ccc
#
0#2
2
2
2
2
2
]
M2
2
2
S
]
M
^
N
Implement this in Mathematica using Nest and Fold.
à Solution
VietaSequence#n_' :
1
r$$$$$$$$$$$$
cccc #Rest$NestList$ 2 . # &, 0, n((
2
Times •• VietaSequence#12' ss N
0.63662
2 s Pi ss N
0.63662
‚ Why is Vieta's formula correct?
We know that
sin+z/
z
z
2 cos- ccccc 1 sin- ccccc 1
2
2
We iterate this formula in Sin:
sin+z/
z
z
z
sin- ccccc 1 2 cos- ccccc 1 sin- ccccc 1
2
4
4
z
z
z
z
z
2 cos- ccccc 1 sin- ccccc 1 22 cos- ccccc 1 cos- ccccc 1 sin- ccccc 1
2
2
2
4
4
lecture07post.nb
2
After n steps, we have
sin+z/
z
z
z
z
2n cos- ccccc 1 cos- ccccc 1 ...#cos- cccccnccc 1 sin- cccccnccc 1
2
4
2
2
We divide both sides by z, and find a limit when n ‘ ˆ:
sin+z/
ccccccccccccccccc
z
z
cc /
z
z
z sin+ cccc
2n
cos- ccccc 1 cos- ccccc 1 ...#cos- cccccnccc 1 cccccccccccccccc
z cccccc
2
4
2
cccc
cc
2n
It follows then
ˆ
z
Ç cos- ccccckccc 1
2
k 1
sin+z/
ccccccccccccccccc
z
We substitute z
ccccS2 :
2
ccccc
S
ˆ
S
cccccc 1
Ç cos- cccccccc
k.1
2
k 1
All that is left to do is to verify that the cosines are nested square roots. Mathematically this would be proved by
induction, based on the formula:
cos+z/
1
'((((((((((((((((((((((((((((((((((
ccccc +cos+2 z/ . 1/(
2
Exercise 2
In 1989 Borwein expressed S as the limit of a sequence defined by an iteration:
lim an
n‘ˆ
1
ccccc
S
where
an
a0
and
+yn . 1/4 an01 0 23.2 +n01/ yn +y2n . yn . 1/
r$$$$
6 0 4# 2
lecture07post.nb
3
4
1 0 %&&&&&&&&&&&&&&&&&&
1 0 y4n01
cccccccccccccccccccccccccccccccc
ccccccccccccc
4
1 . %&&&&&&&&&&&&&&&&&&
1 0 y4n01
r$$$$
2 01
yn
y0
Implement this in Mathematica using Nest and Fold.
à Solution
Clear#a, y, n'; y#n_' :
Nest#+1 0 +1 0 # ^ 4/ ^ +1 s 4// s +1 . +1 0 # ^ 4/ ^ +1 s 4// &, Sqrt#2' 0 1, n'
a#n_' : Fold#
++#1 +y##2' . 1/ ^ 4/ 0 2 ^ +3 . 2#+#2 0 1// y##2' - +y##2' ^ 2 . y##2' . 1/ &/,
6 0 4 Sqrt#2', Table#i, ;i, 1, n?''
The number of significant digits in iteration formula grows quadratically:
$MaxExtraPrecision
200; TableForm#N#Table#1 s a#n' 0 S, ;n, 0, 3?', 22''
00.2273790912166981896610
07.376250956313298951297— 1009
05.472109145689941832749— 10041
02.308580714934390266821— 100171
Fixed Point
A point which does not change upon application of a map. Suppose F is a map, then x- such as
x-
F+x- /
is a fixed point. Consider a continued fraction from the previous lecture
1
cccccccc
1 . cccccccccccccccc
1 ccccc
1. cccccccccccccccc
cccccccc
1 cccc
cccccccc
1. cccccccccccccccc
1 ccccc c
...
cccccccc
cccccccccccccc
1. cccccccc
The fraction is defined by a recurrence relation
xn
1
1 . cccccccccccccc
xn01
x+1/
1
ccc
1 . cccccccc
x+1/
The fixed point x+1/ of this map occurs when
Solving this quadratic equation, gives
lecture07post.nb
4
Solve#x m 1 . 1 s x, x'
1
1
r$$$$
r$$$$
<<x ‘ cccc ,1 0 5 0 , <x ‘ cccc ,1 . 5 0
2
2
N#%'
;;x ‘ 00.618034?, ;x ‘ 1.61803??
In the previous lecture we found this point numerically
NestList#1 . 1 s # &, 1, 15' ss N
;1., 2., 1.5, 1.66667, 1.6, 1.625, 1.61538, 1.61905, 1.61765,
1.61818, 1.61798, 1.61806, 1.61803, 1.61804, 1.61803, 1.61803?
As the alternative to Nest and NestList, Mathematica has FixedPoint function, which is very similar to
Nest except that it continues to apply a given function until the result stop changes. Here we use FixedPoint
to compute the above fraction. NOTE, we use a float 1. as a starting point
FixedPoint#1 . 1 s # &, 1.'
1.61803
otherwise, the iteration will never stop. FixedPoint uses SameQ (===) as the default test for convergence.
However, no two of the rational terms are ever identical.
Similar to NestList, FixedPointList returns a list of the intermediate results
FixedPointList#1 . 1 s # &, 1.'
;1., 2., 1.5, 1.66667, 1.6, 1.625, 1.61538, 1.61905, 1.61765, 1.61818,
1.61798, 1.61806, 1.61803, 1.61804, 1.61803, 1.61803, 1.61803, 1.61803,
1.61803, 1.61803, 1.61803, 1.61803, 1.61803, 1.61803, 1.61803,
1.61803, 1.61803, 1.61803, 1.61803, 1.61803, 1.61803, 1.61803,
1.61803, 1.61803, 1.61803, 1.61803, 1.61803, 1.61803, 1.61803?
Here is another example
xn
x0
2
2 xn01 %&&&&&&&&&&&&&&&&&&&
1 0 xn01
cccc12
FixedPointList#2 ##Sqrt#1 0 # ^ 2' &, 1 s 2'
r$$$$
r$$$$
1
3
3
< cccc , ccccccccc , ccccccccc
2
2
2
lecture07post.nb
5
which shows how dangerous could be the last argument. In this example, the exact number cccc12 words just fine,
but a float won't work at all
FixedPointList#2 ##Sqrt#1 0 # ^ 2' &, 0.5, 50'
;0.5, 0.866025, 0.866025, 0.866025, 0.866025, 0.866025, 0.866025,
0.866025, 0.866025, 0.866025, 0.866025, 0.866025, 0.866025, 0.866025,
0.866025, 0.866025, 0.866025, 0.866025, 0.866025, 0.866025,
0.866025, 0.866025, 0.866025, 0.866025, 0.866025, 0.866025,
0.866025, 0.866025, 0.866025, 0.866025, 0.866025, 0.866025,
0.866026, 0.866025, 0.866026, 0.866024, 0.866028, 0.866019,
0.866037, 0.866002, 0.866073, 0.86593, 0.866216, 0.865643, 0.866789,
0.864493, 0.869066, 0.859847, 0.877992, 0.840546, 0.910715?
FixedPoint accepts a third argument, which terminates the iteration after that particular number of steps. The
another possibility would be to increase the precision of calculations:
FixedPointList#2 ##Sqrt#1 0 # ^ 2' &, N#1 s 2, 20' '
;0.50000000000000000000, 0.8660254037844386468, 0.8660254037844386468?
Newton iteration
We now use Newton's method to find the square root of the number z. This involves solving f +x/
iteratively. The general Newton method is based on this iteration.
xi.1
f +xi /
xi 0 cccccccc
cccccccccc
f … +xi /
For finding the square root, the iteration reduces to
xi.1
Here is the square root of S.
FixedPoint#+# ^ 2 . Pi/ s +2##/ &, 1.'
1.77245
Just 10 iterations give us 100 significant digits:
xi 2 . z
cccccccccccccccccccc
2#xi
x2 0 z
lecture07post.nb
6
Sqrt#Pi' 0 FixedPointList#+# ^ 2 . Pi/ s +2##/ &, N#1, 102''
;0.77245385090551602729816748334114518279754945612238712821380778985g
2911284591032181374950656738544665416,
00.2983424758893805919331542082986062593010352435651657822736645063g
0099691855207231793906675593251386857,
00.0214913054867084276619240515236234023901692593619203236989165720g
0659095408147744460269122361234037404,
00.0001287319765259423873193202602400736804557553067838171982260760g
150128990325681419534138344018851276,
04.6745133175492153099296268207929799171276466989127171722950322376g
470937525542509093247115663— 1009 ,
06.1640743670571561977857153070847440860400933243287569751637284118g
282447194646343018 — 10018 ,
01.0718420900831826125733947315223225442613099599644702680458173597g
5 — 10035 , 03.2408332253247667496820207482— 10071 ,
0. — 100100 , 0. — 100100 ?
Length#%'
10
Now we are going to apply the Newton iteration to the higher order polynomials. The question we are
interested in is: given a starting value, to which root will the solution converge? First we define a function
(according to the Newton method)
Clear[iteration];
iteration[poly_, z_] :=
Function[z,
Evaluate[Together[z - poly/D[poly, z]]]]
where poly is any polynomial, and z is a starting value (a complex number). We will pick z from the
unit square
data
Table#x . I y, ;x, 02., 2., 0.017?, ;y, 02., 2., 0.017?';
and find all fixed points (we restrict our search to 75 iterations) of the cubic:
points#3'
FixedPoint#iteration#z ^ 3 0 1, z', #, 75' & s• data;
To visualize the data in a form of a matrix we use ListDensityPlot:
lecture07post.nb
7
ListDensityPlot#Im#points#3'', Mesh ‘ False,
ColorFunction ‘ Hue, MeshRange ‘ ;;02, 2?, ;02, 2??'
2
1
0
-1
-2
-2
-1
h#DensityGraphics#h
Consider the quadratic:
0
1
2
lecture07post.nb
8
points#4'
FixedPoint#iteration#z ^ 4 0 1, z', #, 75' & s• data;
ListDensityPlot#Im#points#4'', Mesh ‘ False,
ColorFunction ‘ Hue, MeshRange ‘ ;;02, 2?, ;02, 2??';
2
1
0
-1
-2
-2
and the quintic:
-1
0
1
2
lecture07post.nb
9
points#5'
FixedPoint#iteration#z ^ 5 . 1, z', #, 75' & s• data;
ListDensityPlot#Im#points#5'', Mesh ‘ False,
ColorFunction ‘ Hue, MeshRange ‘ ;;02, 2?, ;02, 2??';
2
1
0
-1
-2
-2
-1
0
1
2
These pictures show the convergence to the roots as a function of the complex start value.
Mandelbrot Set
The Mandelbrot set is the set of all complex numbers c for which sequence defined by the iteration
xn.1
x2n . c,
x0
c
remains bounded. This means that there is a number B such that the absolute value of all iterates xn never gets
larger than B. Let us experiment by setting c to different values:
c
1; NestList## ^ 2 . c &, c, 4'
;1, 2, 5, 26, 677?
The sequence is growing and thus unbounded. We can say that c
c
01; NestList## ^ 2 . c &, c, 4'
;01, 0, 01, 0, 01?
1 does not belong to the Mandelbrot set.
lecture07post.nb
10
The sequence oscillates between -1 and 0, so it remains bounded (but it does not converge).
You may ask, what's so special about this iteration. Much of the fascination of the Mandelbrot set is the fact that
an extremely simple formula gives rise to an object of such great complexity.
Let us implement the Mandelbrot set using functions FixedPoint and FixedPointList.
c
0.1; FixedPoint##2 . c &, c'
0.112702
If c
1 is 1 the iteration does not converge. To stop the iteration, we specify the number of steps:
c 1;
FixedPoint##2 . c &, c, 10'
14378219780015246281818710879551167697596193767663736497089725524386g
0876573905561522930787231532934233533308798566631644068096156880822g
97859526620035327291442156498380795040822304677
Another tool to stop iteration is to use the option SameTest:
c 1;
FixedPoint##2 . c &, c, SameTest ‘ +Abs##2 0 #1' ! 10 &/'
26
The function Abs##2 0 #1' ! 10 & inside of SameTest means that we stop iterations when the difference
between two steps is greater than 10.
Here is the Mathematica definition for the Mandelbrot function
Mandelbrot#c_' : Length#FixedPointList##2 . c &, c, 80,
SameTest ‘ +Abs##2 0 #1' ! 5. «« Abs##2 0 #1' ? 10 ^ 06. &/''
Note, that we are interested in the number of iterations that it takes until a fixed point has been reached. That's
why we wrapped Length around FixedPointList. We are using SameTest to terminate recursion if the
distance between two iterations is bigger than 5. Also we set the limit of iterations to 80.
lecture07post.nb
DensityPlot#0Mandelbrot#x . y I',
;x, 01.5, 0.5?, ;y, 01, 1?, Mesh ‘ False, Frame ‘ False,
AspectRatio ‘ Automatic, PlotPoints ‘ 125';
Different shadows of gray correspondent to a different number of iterations. If you want to see a colorful picture,
you add ColorFunction ‘ Hue to it:
11
lecture07post.nb
12
DensityPlot#0Mandelbrot#x . y I', ;x, 0.2, 0.4?,
;y, 0.5, 0.65?, Mesh ‘ False, Frame ‘ False,
AspectRatio ‘ Automatic, ColorFunction ‘ Hue, PlotPoints ‘ 200'
h#DensityGraphics#h
Exercise 3
Find all fixed points of the second order of the Mandelbrot map.
xn.1
x2n . c
Points which are invariant after two iterations.
à Solution
After two iterations:
xn.2
2
xn.1
.c
2
+x2n . c/ . c
Solve#z m +z ^ 2 . c/ ^ 2 . c, z'
1
1
r$$$$
r$$$$
<;z ‘ +01/1s3 ?, ;z ‘ 0+01/2s3 ?, <z ‘ cccc ,01 0 Ç 7 0 , <z ‘ cccc ,01 . Ç 7 0
2
2
lecture07post.nb
13
Solve#z m z ^ 2 . c, z'
;;z ‘ +01/1s3 ?, ;z ‘ 0+01/2s3 ??
c
1
r$$$$$$$$$$$$$$$$$$$
1 s 2; cccc ,01 0 03 0 4 c 0
2
1
r$$$$
cccc ,01 0 Ç 5 0
2
1
Ç
FixedPointList$#2 . c &, cccc . cccc , 5(
2
2
Ç
Ç
1
1
< cccc . cccc , cccc . cccc
2
2
2
2
1
r$$$$
2
FixedPoint$+#2 . c / . c &, cccc ,01 0 Ç 5 0, 2( ss N
2
00.5 0 1.11803 Ç
1
r$$$$$$$$$$$$$$$$$$$
cccc ,01 0 03 0 4 c 0 ss N
2
00.5 0 1.11803 Ç