Professional Documents
Culture Documents
Slide 1 of 5
Lecture 5
Analysis of Iterates
Brian G. Higgins
Department of Chemical Engineering & Materials Science
University of California, Davis
April 2014, Hanoi, Vietnam
ECM6Lecture5Vietnam_2014.nb
ECM6Lecture5Vietnam_2014.nb
A Recursive Algorithm
Remove@g, iteratesD
Background
To begin our discussion let us look at the following general recursive algorithm
xn+1 = g Hp, b, xn L =
1
p
Hp - 1L xn +
b
xn
Example
To begin our discussion let us look at the following general recursive algorithm
xn+1 = g Hp, b, xn L =
1
p
Hp - 1L xn +
b
xn
We saw this formula in Lecture 3. It is used to compute the square root of a real number b.
The parameter p in the recursive algorithm influences the order of convergence.
When xn+1 = xn we say that the iteration has converged to a stable fixed point.
We define in Mathematica the function gHp, b, xn L
g@p_, b_, x_D :=
1
p
Hp - 1L x +
b
x
1
p
Hp - 1L x +
b
x
The value of x that satisfies the above equation is called a fixed point
We can use Mathematica's Solve function
ECM6Lecture5Vietnam_2014.nb
Solve@g@p, b, xD x, xD
99x -
b =, 9x
b ==
There are two fixed points. Note that the fixed points do not depend on the parameter p.
Application of NestList
How do we program Mathematica to produce the iterates?
In Lecture 4 we discussed the use of NestList to generate iterates:
NestList[f, expr, n]
gives a list of the results of applying
f to expr 0 through n times.
Since NestList takes a function with a single argument, we use NestList with a pure function:
iterates = NestList@g@1.5, 78.8, D &, 2, 20D
82, 26.9333, 10.9283, 8.44986, 9.03369, 8.8265, 8.89394,
8.87129, 8.87882, 8.87631, 8.87715, 8.87687, 8.87696, 8.87693,
8.87694, 8.87694, 8.87694, 8.87694, 8.87694, 8.87694, 8.87694<
b =
78.8 = 8.87693640846886
ECM6Lecture5Vietnam_2014.nb
Partition Function
We can accomplish this structure using the Partition function, with the appropriate arguments:
Partition@iterates, 2, 1D
882, 26.9333<, 826.9333, 10.9283<, 810.9283, 8.44986<, 88.44986, 9.03369<,
89.03369, 8.8265<, 88.8265, 8.89394<, 88.89394, 8.87129<, 88.87129, 8.87882<,
88.87882, 8.87631<, 88.87631, 8.87715<, 88.87715, 8.87687<, 88.87687, 8.87696<,
88.87696, 8.87693<, 88.87693, 8.87694<, 88.87694, 8.87694<, 88.87694, 8.87694<,
88.87694, 8.87694<, 88.87694, 8.87694<, 88.87694, 8.87694<, 88.87694, 8.87694<<
xk+1 - xk
We achieve this data structure by making use of a replacement rule (see Lecture 2) with an appropriate
pattern:
Dxk = Partition@iterates, 2, 1D . 8xk1_, xk2_< 8Abs@xk2 - xk1D< Flatten
924.9333, 16.0051, 2.47841, 0.583825, 0.207185, 0.0674407, 0.0226507, 0.00753095,
0.00251245, 0.000837245, 0.000279108, 0.0000930331, 0.0000310113, 0.0000103371,
3.4457 10-6 , 1.14857 10-6 , 3.82855 10-7 , 1.27618 10-7 , 4.25395 10-8 , 1.41798 10-8 =
Note that the absolute difference diminishes with the number of iterates. Thus we can use such metric
to determine if our iteration scheme has converged.
Speed of Convergence
To get an indication of the "speed" of convergence, we again use Partition to interrogate the absolute
difference of and two successive iterates and then examine the ratio of the absolute difference, as
shown below
Partition@Dxk , 2, 1D . 8xk1_, xk2_< 8xk1 xk2<
881.55784<, 86.45779<, 84.24513<, 82.81789<, 83.07211<,
82.97742<, 83.00768<, 82.99746<, 83.00085<, 82.99972<, 83.00009<,
82.99997<, 83.00001<, 83.<, 83.<, 83.<, 83.<, 83.<, 83.<<
ECM6Lecture5Vietnam_2014.nb
= CL 3.0
Let us put all these steps together in a compound function that depends on the parameter p
convergenceTest@p_D :=
Take@Partition@Flatten@HPartition@NestList@g@p, 78.8, D &, 2, 10D, 2, 1D .
8xk1_, xk2_< 8Abs@xk1 - xk2D<LD, 2, 1D . 8xk1_, xk2_< 8xk1 xk2<, - 1D
res = Table@Flatten@8p, convergenceTest@pD<D, 8p, 0.5, 5, .11<D
880.5, 1.04619<, 80.61, 2.53484<, 80.72, 0.71611<, 80.83, 0.829812<, 80.94, 0.910497<,
81.05, 1.07508<, 81.16, 1.36332<, 81.27, 1.73881<, 81.38, 2.22755<,
81.49, 2.9225<, 81.6, 4.00025<, 81.71, 5.89657<, 81.82, 10.1111<, 81.93, 27.5715<,
82.04, 51.0007<, 82.15, 14.3333<, 82.26, 8.69221<, 82.37, 6.40516<,
82.48, 5.16619<, 82.59, 4.38904<, 82.7, 3.85598<, 82.81, 3.46757<, 82.92, 3.17192<,
83.03, 2.93933<, 83.14, 2.75157<, 83.25, 2.59683<, 83.36, 2.4671<, 83.47, 2.3568<,
83.58, 2.26188<, 83.69, 2.17935<, 83.8, 2.10695<, 83.91, 2.04294<, 84.02, 1.98596<,
84.13, 1.93493<, 84.24, 1.88896<, 84.35, 1.84737<, 84.46, 1.80955<,
84.57, 1.77503<, 84.68, 1.74341<, 84.79, 1.71433<, 84.9, 1.68751<<
Plotting Data
We would like to plot the descrete data points shown above. To do so we make use of the function
? ListPlot
ListPlot@8y1 , y2 , <D plots points corresponding to a list of values, assumed to correspond to x coordinates 1, 2, .
ListPlot@88x1 , y1 <, 8x2 , y2 <, <D plots a list of points with specified x and y coordinates.
ListPlot@8list1 , list2 , <D plots several lists of points.
40
30
CL
20
10
0
1
p
Clearly we have rapid convergence near p=2. Let see what is happening at p=2
ECM6Lecture5Vietnam_2014.nb
To within machine precision (16 digits) the difference between iterates has gone to zero
Partition@iterates, 2, 1D . 8xk1_, xk2_< 8Abs@xk1 - xk2D<
9818.7<, 88.44662<, 82.91125<, 80.453611<,
80.0115747<, 97.5461 10-6 =, 93.2081 10-12 =, 80.<, 80.<, 80.<=
ECM6Lecture5Vietnam_2014.nb
Background
The steady state temperature in a rod of material of length L with an embedded heat source is given by
T2 = Cosh J 0.5 L T2 N
Find the all possible steady state temperatures.
Note the steady state temperature is the value of T that satisfies the above equation
Solution
First we make the substitution
u = T2
so that the steady state temperature becomes
u = Cosh J 0.5 L uN
We can get an estimate of the steady state temperatures by plotting the LHS and RHS of the above
equation as a function of T and looking for points were the two curves intersect for a specified rod
length L.
Using Solve
As illustrated below, the fixed points for this iteration scheme cannot be found using the function Solve:
SolveBu CoshB
Solve::inex :
Solve was unable to solve the system with inexact coefficients or the system obtained by direct rationalization
of inexact numbers present in the system. Since many of the methods used by Solve
require exact input, providing Solve with an exact version of the system may help.
But we can use a plotting function to examine the roots. That is, we plot the LHS and RHS of the equation for a given value of L
u = Cosh J 0.5 L uN
and the intersection points of the two curves are the desired roots.
ECM6Lecture5Vietnam_2014.nb
PlotB:u, CoshB
LHS or RHS
30
25
20
15
10
5
0
0
10
15
20
u
Thus we have steady solutions near u=1 (1.02478) and u=16 (15.9743).
Let us iterate the function and see if we can find the fixed point (steady solutions)
0.5 L uF
Summary
Thus our iteration method for finding the fixed points of
10
ECM6Lecture5Vietnam_2014.nb