October 19, 2011 Lecture Note

LN16-PHYS3330-501-2010®
10/19, 2011
Professor Xinchou Lou
Remind All Students:
• Homework assignment 6 due today
• Extend the due date for HW7 to October 31
Review of Last Class
• None.
Today's Lecture
• extrema
• zeros
Reading Assignment
• None.
Part II. Deterministic Process
Chapter 6 Extrema and Zeros
Fundamentals and Algorithms:
(1) Finding extremum
(2) Finding zeros
(3) Numerical integration
(4) Numerical optimization
Part II. Deterministic Process
Chapter 6 Extrema and Zeros
Review of Last Class:
• Finding real zeros of Non-linear Equations
The Bisection Method
The bisection method begins with an interval ( x1, x2 ) in which the function
changes sign, which is
f ( x1) f ( x2 ) < 0
We then pick the midpoint x3 (bisect of the interval) and evaluate the
function there, If
f ( x1) f ( x3 ) < 0 then there is sign change in (x1, x3 )
f ( x1) f ( x3 ) > 0 then there is sign change in (x3 , x2 )
f ( x1) f ( x3 ) = 0 then x3 is a zero
Then we keep (x1, x3 ) (the one change sign), and repeat the steps until
cutoff
| f ( xk +1 ) − f ( xk ) |< δ error
, then stop p = xk +1 + xk .
2
Problem: if there are several zeros and the choice of interval steps
are over more than 1 zeros, then one only find one of these zeros.
Newton's Method
The mathematical notation the tangent line at xk is
y( x) = f ( xk ) + f ' ( xk )( x − xk )
and hence solving for x = xk +1 , the next approximation is
xk +1 = xk −
f ( xk )
f ' ( xk )
Note:
(1)
If Newton's method converges, it finds a root very quickly.
(2)
It sometimes diverges, when f '( xn ) ≅ 0 , and fails to find
root.
(3)
If the 1st trail value, x1, is sufficiently close to the root, it is
guaranteed to converge.
Newton's method is faster than the bisection method, but it has flaws.
Modified Newton's Method: The beginning of the next step in the iteration
process involves the evaluation of | f ( x) | at the new point. If this new value is
not smaller in size than the previous value, we will not accept the step, but
instead we will go back and halve the step
xk +1 − xk = ∆xk = −
using instead ∆xk / 2
f ( xk )
f ' ( xk )
Newton’s Method for Multi-Function and Multi-variables
Function vector
f ( x ) = [ f1( x ), f 2 ( x ),..., f n ( x )]
has a zero at x * such that
f ( x* ) = [0,0,...,0]
Example:
f1( x, y, z) = 5xy − z − 5 = 0
f 2( x, y, z) = y2 − 6 xyz = 0
f 3( x, y, z) = yz +10 x + 20 = 0
Let ( x1 is the approximate root)
δ x = x1 − x*
⇒
x* = x1 − δ x
Then
*
f ( x ) = f ( x1 − δ x ) = f ( x1) − δ x ⋅ D( x1) + O{| δ x |2}
where
Dij ( x ) = ∂∂x [ f j ( x)] (Jacobian Matrix Elements)
i
are the elements of the Jacobian matrix. By dropping the error
to take an approximation
δ x ≅ f ( x1) ⋅ D −1( x1)
Repeatedly
x2 = x1 − δ x ≅ x1 − f ( x1) ⋅ D −1( x1)
The iteration can continue until a desired precision is reached.
Example:
Implementation of Newton's Method (non-linear equation)
 
 f1   σ ( y − x) 
f =  f 2  =  rx − y − xz 
  

 f 3   xy − bz 
(r=28, σ =10, b=8/3)
There are three true roots for the function:

0,0,0




x =  x, y, z  =  6 2,6 2,27

 


  −6 2, −6 2,27

The Jacobian matrix
 ∂f
 1
 ∂x
 ∂f
D= 1
 ∂y

 ∂f1
 ∂z

∂f 2
∂x
∂f 2
∂y
∂f 2
∂z
∂f 3 

∂x  
−σ r − z y 
∂f 3  
=  σ −1 x 
∂y  
− x −b 
  0
∂f 3 
∂z 
Steps:
(1)
(2)
set initial guess x = [50,50,50] and λ = [σ , r, b]
loop over desired number of steps
evaluate f ( xn ; λ ) and D3×3
find δ x ≅ f ( xi ) ⋅ D−1( xi ) by Gaussian elimination
update the estimate for the root as xn+1 = xn − δ x
(3)
(4)
print the final estimate for the root
plot the iterations from the initial guess to final estimate
A simple C# program:
using
using
using
using
System;
System.Collections.Generic;
System.Text;
System.IO;
namespace Phys33330App
{
class Program
{
public class MultiVariableNewtonMethod
{
private double function1(double x, double y)
{
return 10.0 * (y - x);
}
private double function2(double x, double y, double z)
{
return 28.0 * x - y - x * z;
}
private double function3(double x, double y, double z)
{
return x * y - 8.0 * z / 3.0;
}
public bool FindZeros(double x, double y, double z, double
precision)
{
double D, d11, d12, d13, d21, d22, d23, d31, d32, d33;
double f1, f2, f3;
double deltax, deltay, deltaz;
int MAXIMUM = 10000;
System.Console.WriteLine("\n x = " + x + ", y = " + y + ",
z = " + z);
System.Console.WriteLine("\n f1 = " + function1(x, y) + ",
f2 = " + function2(x, y, z) + ", f3 = " + function3(x, y, z));
for (int i = 0; i < MAXIMUM; i++)
{
f1 = function1(x, y);
f2 = function2(x, y, z);
f3 = function3(x, y, z);
D =
(28.0 - z) / 3.0;
d11
d21
d31
d12
d22
d32
d13
-80.0 / 3.0 - 10.0 * x * y - 10.0 * x * x + 80.0 *
=
=
=
=
=
=
=
8.0 / 3.0 + x * x;
80.0 / 3.0;
-10.0 * x;
-x * y + 8.0 * (28.0 - z) / 3.0;
80.0 / 3.0;
-10.0 * x;
x * (28.0 - z) + y;
d23 = 10.0 * (x + y);
d33 = -270.0 + 10.0 * z;
deltax = (f1 * d11 + f2 * d21 + f3 * d31) / D;
deltay = (f1 * d12 + f2 * d22 + f3 * d32) / D;
deltaz = (f1 * d13 + f2 * d23 + f3 * d33) / D;
x = x - deltax;
y = y - deltay;
z = z - deltaz;
f1 = function1(x, y);
f2 = function2(x, y, z);
f3 = function3(x, y, z);
System.Console.WriteLine("\n Iteration i = " + (i + 1));
System.Console.WriteLine("\n x = " + x + ", y = " + y +
", z = " + z);
System.Console.WriteLine("\n f1 = " + f1 + ", f2 = " +
f2 + ", f3 = " + f3);
if (Math.Abs(f1) < precision &&
&& Math.Abs(f3) < precision)
{
System.Console.WriteLine("\n
System.Console.WriteLine("\n
1));
System.Console.WriteLine("\n
+ ", z = " + z);
System.Console.WriteLine("\n
+ f2 + ", f3 = " + f3);
Math.Abs(f2) < precision
Final answer: ");
Iteration i = " + (i +
x = " + x + ", y = " + y
f1 = " + f1 + ", f2 = "
return true;
}
}
return true;
}
}
static void Main(string[] args)
{
MultiVariableNewtonMethod mvnm = new
MultiVariableNewtonMethod();
mvnm.FindZeros(50.0, 50.0, 50.0, 0.00001);
return;
}
}
}
Program output:
x = 50, y = 50, z = 50
f1 = 0, f2 = -1150, f3 = 2366.66666666667
Iteration i = 1
x = 26.0142255005269, y = 26.0142255005269, z = 38.0334562697576
f1 = 0, f2 = -287.026819451677, f3 = 575.317378339576
Iteration i = 2
x = 14.6382666558615, y = 14.6382666558615, z = 31.8249041447202
f1 = 0, f2 = -70.6282334593856, f3 = 129.41243963552
Iteration i = 3
x = 9.9200926884212, y = 9.9200926884212, z = 28.5551525099386
f1 = 0, f2 = -15.4272570432219, f3 = 22.2611655870315
Iteration i = 4
x = 8.6165121313661, y = 8.6165121313661, z = 27.2043596404676
f1 = 0, f2 = -1.76086732125106, f3 = 1.6993222687321
Iteration i = 5
x = 8.48675691308981, y = 8.48675691308981, z = 27.0030774319529
f1 = 0, f2 = -0.026117416900945, f3 = 0.0168364166699462
Iteration i = 6
x = 8.48528158655874, y = 8.48528158655874, z = 27.0000005349767
f1 = 0, f2 = -4.53942777767224E-06, f3 = 2.17658836731971E-06
Final answer:
Iteration i = 6
x = 8.48528158655874, y = 8.48528158655874, z = 27.0000005349767
f1 = 0, f2 = -4.53942777767224E-06, f3 = 2.17658836731971E-06
How to find the other two zeros?
To find other zeros, we use different initial (x, y, z)
Program output:
x = 2, y = 2, z = 5
f1 = 0, f2 = 44, f3 = -9.33333333333333
Iteration i = 1
x = -0.68421052631579, y = -0.68421052631579, z = 2.52631578947368
f1 = 0, f2 = -20.202216066482, f3 = 7.20498614958449
Iteration i = 2
x = -0.0551295457186011, y = -0.0551295457186011, z = 0.147263855001743
f1 = 0, f2 = -1.49661632382925, f3 = 0.395742880149122
Iteration i = 3
x = -0.000296767785251804, y = -0.000296767785251804, z = 0.00112745454928864
f1 = 0, f2 = -0.00801306479398828, f3 = 0.00300663353588808
Iteration i = 4
x = -1.23914229024176E-08, y = -1.23914229024176E-08, z = 3.30239113546446E-08
f1 = 0, f2 = -3.34568418774487E-07, f3 = 8.8063763765933E-08
Final answer:
Iteration i = 4
x = -1.23914229024176E-08, y = -1.23914229024176E-08, z = 3.30239113546446E-08
f1 = 0, f2 = -3.34568418774487E-07, f3 = 8.8063763765933E-08
Program output:
x = -50, y = -50, z = 10
f1 = 0, f2 = -850, f3 = 2473.33333333333
Iteration i = 1
x = -25.4978471474704, y = -25.4978471474704, z = 18.6692680301399
f1 = 0, f2 = -212.415730394037, f3 = 600.355494408725
Iteration i = 2
x = -13.96374743568, y = -13.96374743568, z = 23.2315448572254
f1 = 0, f2 = -52.6217558363943, f3 = 133.035456161524
Iteration i = 3
x = -9.44349569573819, y = -9.44349569573819, z = 25.7801006861171
f1 = 0, f2 = -11.5201139198868, f3 = 20.4326757924466
Iteration i = 4
x = -8.51699725146238, y = -8.51699725146238, z = 26.8803160553146
f1 = 0, f2 = -1.01934782792981, f3 = 0.858399367245497
Iteration i = 5
x = -8.48527063137805, y = -8.48527063137805, z = 26.9995541659894
f1 = 0, f2 = -0.00378302223694504, f3 = 0.00100657842196483
Iteration i = 6
x = -8.48528137433407, y = -8.48528137433407, z = 27.0000000005645
f1 = 0, f2 = 4.78956962979282E-09, f3 = 1.15406351142155E-10
Final answer:
Iteration i = 6
x = -8.48528137433407, y = -8.48528137433407, z = 27.0000000005645
f1 = 0, f2 = 4.78956962979282E-09, f3 = 1.15406351142155E-10
• Finding complex zeros
From y = f ( x) to w( z ) = u ( x, y ) + iv( x, y ) , where z = x + iy .
To find complex zero, we find
w( z ) = 0
which is equivalent to the two simultaneous conditions
u ( x, y ) = 0
v ( x, y ) = 0
the u ( x, y) is called the real part and the v( x, y ) is called the
imaginary part of w( z )
We can use Newton’s Method for Multi-Function and Multivariables with
f 1 = u ( x, y )
f 2 = v ( x, y )
Example:
Find u ( x, y) and v( x, y ) , if w = z
3
w = z3 = ( x + iy)3 = x3 + 3x2iy + 3x(iy)2 + (iy)3
= x3 + 3ix 2 y − 3xy 2 − iy3 = x3 − 3xy 2 + i(3x 2 y − y 3 )
Then
u ( x, y ) = x 3 − 3 xy 2
v ( x, y ) = 3 x 2 y − y 3
The crude method
In the complex plane for each point x + iy we record the
quadrant number in which the function value falls. Thus at each
point, we record 1, 2, 3, and 4, and we record a 0 whenever
either u ( x, y ) = 0 or v( x, y ) = 0 or both. This produce a picture of a
region with numbers attached to each mesh point.
The u ( x, y ) = 0 curves divide quadrants 1 and 2, and 3 and 4.
The v( x, y ) = 0 curves divide quadrants 1 and 4, and 2 and 3.
The intersection of u ( x, y ) = 0 curve and v( x, y ) = 0 curve is the
complex zero.