chapter 12 iterative methods for system of equations

55
Chapter 12 Chapter 12 Iterative Methods Iterative Methods for System of for System of Equations Equations

Post on 18-Dec-2015

228 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Chapter 12 Iterative Methods for System of Equations

Chapter 12Chapter 12

Iterative Methods for Iterative Methods for System of EquationsSystem of Equations

Page 2: Chapter 12 Iterative Methods for System of Equations

Iterative Methods for Solving Iterative Methods for Solving Matrix EquationsMatrix Equations

0C , dCxx bAx

ii

Jacobi methodGauss-Seidel Method*Successive Over Relaxation (SOR)MATLAB’s Methods

Page 3: Chapter 12 Iterative Methods for System of Equations

Iterative MethodsIterative Methods

4444343242141

3434333232131

2424323222121

1414313212111

bxaxaxaxa

bxaxaxaxa

bxaxaxaxa

b xaxaxaxa

4434324214144

3343423213133

2242432312122

1141431321211

a/)xaxaxab(x

a/)xaxaxab(x

a/)xaxaxab(x

a/)xaxaxab(xCan be converted to

Page 4: Chapter 12 Iterative Methods for System of Equations

Idea behind iterative methods: Convert Ax = b into x = Cx +d

Generate a sequence of approximations (iteration) x1, x2, …., with initial x0

Similar to fix-point iteration method

Iterative Methods Iterative Methods

dCxx bAx Equivalent system

dCxx 1jj

Page 5: Chapter 12 Iterative Methods for System of Equations

Rearrange Matrix EquationsRearrange Matrix Equations

Rewrite the matrix equation in the same way

4444343242141

3434333232131

2424323222121

1414313212111

bxaxaxaxabxaxaxaxabxaxaxaxabxaxaxaxa

44

43

44

432

44

421

44

414

33

34

33

342

33

321

33

313

22

24

22

243

22

231

22

212

11

14

11

143

11

132

11

121

a

b x

a

ax

a

ax

a

ax

a

bx

a

a x

a

ax

a

ax

a

bx

a

ax

a

a x

a

ax

a

bx

a

ax

a

ax

a

a x

n equations

n variables

Page 6: Chapter 12 Iterative Methods for System of Equations

44

4

33

3

22

2

11

1

44

43

44

42

44

41

33

34

33

32

33

31

22

24

22

23

22

21

11

14

11

13

11

12

a

ba

ba

ba

b

d ;

0a

a

a

a

a

aa

a 0

a

a

a

aa

a

a

a0

a

aa

a

a

a

a

a 0

C

Iterative MethodsIterative Methods

x and d are column vectors, and C is a square matrix

0C ;dCxx bAx ii1jj

Page 7: Chapter 12 Iterative Methods for System of Equations

ConvergenceConvergence CriterionCriterion

For system of equations

j 1i

a,i iji

x1 100% for x

x

2 Norm of the residual vector

all

Ax

ji

s

s

x

b

)C(eig ,1i

Page 8: Chapter 12 Iterative Methods for System of Equations

Jacobi MethodJacobi Method

44old

343old

242old

1414new

4

33old

434old

232old

1313new

3

22old

424old

323old

1212new

2

11old

414old

313old

2121new

1

axaxaxabx

axaxaxabx

axaxaxabx

axaxaxabx

/)(

/)(

/)(

/)(

Page 9: Chapter 12 Iterative Methods for System of Equations

Gauss-Seidel MethodGauss-Seidel Method

44new

343new

242new

1414new

4

33old

434new

232new

1313new

3

22old

424old

323new

1212new

2

11old

414old

313old

2121new

1

axaxaxabx

axaxaxabx

axaxaxabx

axaxaxabx

/)(

/)(

/)(

/)(

Differ from Jacobi method by sequential updating: use new xi immediately as they become available

Page 10: Chapter 12 Iterative Methods for System of Equations

Gauss-Seidel MethodGauss-Seidel Method

44j

343j

242j

1414j

4

331j

434j

232j

1313j

3

221j

4241j

323new

1212j

2

111j

4141j

3131j

2121j

1

axaxaxabx

axaxaxabx

axaxaxabx

axaxaxabx

/)(

/)(

/)(

/)(

use new xi at jth iteration as soon as they become available

isji

1ji

ji

ia, x all for 100x

xx

%

Page 11: Chapter 12 Iterative Methods for System of Equations

(a) Gauss-Seidel Method (b) Jacobi Method

Page 12: Chapter 12 Iterative Methods for System of Equations

Convergence and Diagonal DominantConvergence and Diagonal Dominant

Sufficient condition -- A is diagonally dominantDiagonally dominant: the magnitude of the diagonal

element is larger than the sum of absolute value of the other elements in the row

Necessary and sufficient condition -- the magnitude of the largest eigenvalue of C (not A) is less than 1

Fortunately, many engineering problems of practical importance satisfy this requirement

Use partial pivoting to rearrange equations!

n

ij1i

ijii aa

Page 13: Chapter 12 Iterative Methods for System of Equations

Convergence or Divergence of Jacobi and Convergence or Divergence of Jacobi and Gauss-Seidel MethodsGauss-Seidel Methods

Same equations, but in different order Rearrange the order of the equations to ensure convergence

Page 14: Chapter 12 Iterative Methods for System of Equations

9323

31261

52101

3218

A

is strictly diagonally dominant because diagonal elements are greater than sum of absolute value of other elements in row

is not diagonally dominant

Diagonally Dominant MatrixDiagonally Dominant Matrix

9323

31261

5261

3218

A

Page 15: Chapter 12 Iterative Methods for System of Equations

Example:

12x6x x3

7x x4x2

10x2x2x5

321

321

321

6

12 x

6

1x

6

3 x

4

7 x

4

1 x

4

2 x

5

10x

5

2x

5

2 x

old2

old1

new3

old3

old1

new2

old3

old2

new1

Jacobi Gauss-Seidel

6

12 x

6

1x

6

3 x

4

7 x

4

1 x

4

2 x

5

10x

5

2x

5

2 x

new2

new1

new3

old3

new1

new2

old3

old2

new1

Jacobi and Gauss-SeidelJacobi and Gauss-Seidel

Page 16: Chapter 12 Iterative Methods for System of Equations

ExampleExample

Not diagonally dominant !!Order of the equation can be importantRearrange the equations to ensure convergence

086

114

1205

45x8x6

2xxx4

80x12x5

21

321

31

1205

086

114

80x12x5

45x8x6

2xxx4

31

21

321

Page 17: Chapter 12 Iterative Methods for System of Equations

Gauss-Seidel IterationGauss-Seidel Iteration

12/)x580(x

8/)x645(x

4/)2xx(x

13

12

321

Assume x1 = x2 = x3 = 0

Rearrange

4583.612/)5.0(580x

0.68/)5.0(645x

5.04/)200(x

3

2

1First iteration

Page 18: Chapter 12 Iterative Methods for System of Equations

Gauss-Seidel MethodGauss-Seidel Method

7561.712/))6146.2(580(x

6641.38/))6146.2(645(x

6146.24/)4583.662(x

3

2

1

6479.712/))3550.2(580(x

8587.38/))3550.2(645(x

3550.24/)7561.76641.32(x

3

2

1

6569.712/))3767.2(580(x

8425.38/))3767.2(645(x

3767.24/)6479.78587.32(x

3

2

1

Second iteration

Third iteration

Fourth iteration

6562.7x ,8438.3x ,3750.2x :th7

6563.7x ,8437.3x ,3750.2x :th6

6562.7x ,8439.3x ,3749.2x :th5

321

321

321

Page 19: Chapter 12 Iterative Methods for System of Equations

MATLAB M-File for Gauss-Seidel methodMATLAB M-File for Gauss-Seidel method

Continued on next page

Page 20: Chapter 12 Iterative Methods for System of Equations

MATLAB M-File for Gauss-Seidel methodMATLAB M-File for Gauss-Seidel method

Continued from previous page

Page 21: Chapter 12 Iterative Methods for System of Equations

» A = [4 –1 –1; 6 8 0; -5 0 12];

» b = [-2 45 80];

» x=Seidel(A,b,x0,tol,100);

i x1 x2 x3 x4 ....

1.0000 -0.5000 6.0000 6.4583

2.0000 2.6146 3.6641 7.7561

3.0000 2.3550 3.8587 7.6479

4.0000 2.3767 3.8425 7.6569

5.0000 2.3749 3.8439 7.6562

6.0000 2.3750 3.8437 7.6563

7.0000 2.3750 3.8438 7.6562

8.0000 2.3750 3.8437 7.6563

Gauss-Seidel method converged

Gauss-Seidel Iteration

Converges faster than the Jacobi method shown in next page

Page 22: Chapter 12 Iterative Methods for System of Equations

» A = [4 –1 –1; 6 8 0; -5 0 12];» b = [-2 45 80];» x=Jacobi(A,b,0.0001,100); i x1 x2 x3 x4 .... 1.0000 -0.5000 5.6250 6.6667 2.0000 2.5729 6.0000 6.4583 3.0000 2.6146 3.6953 7.7387 4.0000 2.3585 3.6641 7.7561 5.0000 2.3550 3.8561 7.6494 6.0000 2.3764 3.8587 7.6479 7.0000 2.3767 3.8427 7.6568 8.0000 2.3749 3.8425 7.6569 9.0000 2.3749 3.8438 7.6562 10.0000 2.3750 3.8439 7.6562 11.0000 2.3750 3.8437 7.6563 12.0000 2.3750 3.8437 7.6563 13.0000 2.3750 3.8438 7.6562 14.0000 2.3750 3.8438 7.6562

Jacobi method converged

Jacobi Iteration

Page 23: Chapter 12 Iterative Methods for System of Equations

Relaxation MethodRelaxation Method

Relaxation (weighting) factor Gauss-Seidel method: = 1Overrelaxation 1 < < 2Underrelaxation 0 < < 1

Successive Over-relaxation (SOR)

oldi

newi

newi x1xx )(

Page 24: Chapter 12 Iterative Methods for System of Equations

Successive Over Relaxation Successive Over Relaxation (SOR)(SOR)

Relaxation method

44new

343new

242new

1414old

4new

4

33old

434new

232new

1313old

3new

3

22old

424old

323new

1212old

2new

2

11old

414old

313old

2121old

1new

1

)/axaxaxa(b)x(1x

)/axaxaxa(b)x(1x

)/axaxaxa(b)x(1x

)/axaxaxa(b)x(1x

2 2 21 1 23 3 24 4 22

2 2 2

2 2 21 1 23 3 24 4 22

G-S method ( ) /

SOR method (1 )

(1 ) ( ) /

new new old old

new old new

old new old old

x b a x a x a x a

x x x

x b a x a x a x a

Page 25: Chapter 12 Iterative Methods for System of Equations

SOR IterationsSOR Iterations

12/)x580(x

8/)x645(x

4/)2xx(x

13

12

321

Assume x1 = x2 = x3 = 0, and = 1.2

Rearrange

7.712/)6.0(5802.10)2.0(x

29.78/)6.0(6452.10)2.0(x

6.04/)200(2.10)2.0(x

3

2

1

First iteration

Seidel-Gauss :S-G x 1x x oldi

SGii ;

Page 26: Chapter 12 Iterative Methods for System of Equations

SOR IterationsSOR Iterations

4685.812/))017.4(580(2.1)7.7()2.0(x

6767.18/))017.4(645(2.1)29.7()2.0(x

017.44/)27.729.7(2.1)6.0()2.0(x

3

2

1

Second iteration

Third iteration

1264.712/))6402.1(580(2.1)4685.8()2.0(x

9385.48/))6402.1(645(2.1)6767.1()2.0(x

6402.14/)24685.86767.1(2.1)017.4()2.0(x

3

2

1

Converges slower !! (see MATLAB solutions)

There is an optimal relaxation parameter

Page 27: Chapter 12 Iterative Methods for System of Equations

Successive Over RelaxationSuccessive Over Relaxation

Relaxation factor w (= )

Page 28: Chapter 12 Iterative Methods for System of Equations

» [A,b]=Example

A = 4 -1 -1 6 8 0-5 0 12

b = -2 45 80

» x0=[0 0 0]'x0 = 0 0 0» tol=1.e-6tol = 1.0000e-006

» w=1.2; x = SOR(A, b, x0, w, tol, 100); i x1 x2 x3 .... 1.0000 -0.6000 7.2900 7.7000 2.0000 4.0170 1.6767 8.4685 3.0000 1.6402 4.9385 7.1264 4.0000 2.6914 3.3400 7.9204 5.0000 2.2398 4.0661 7.5358 6.0000 2.4326 3.7474 7.7091 7.0000 2.3504 3.8851 7.6334 8.0000 2.3855 3.8261 7.6661 9.0000 2.3705 3.8513 7.6521 10.0000 2.3769 3.8405 7.6580 11.0000 2.3742 3.8451 7.6555 12.0000 2.3753 3.8432 7.6566 13.0000 2.3749 3.8440 7.6561 14.0000 2.3751 3.8436 7.6563 15.0000 2.3750 3.8438 7.6562 16.0000 2.3750 3.8437 7.6563 17.0000 2.3750 3.8438 7.6562 18.0000 2.3750 3.8437 7.6563 19.0000 2.3750 3.8438 7.6562 20.0000 2.3750 3.8437 7.6563 21.0000 2.3750 3.8438 7.6562

SOR method converged

SOR with SOR with = 1.2 = 1.2

Converge Slower !!

Page 29: Chapter 12 Iterative Methods for System of Equations

» [A,b]=Example2

A =

4 -1 -1 6 8 0 -5 0 12

b = -2 45 80

» x0=[0 0 0]'

x0 = 0 0 0

» tol=1.e-6

tol = 1.0000e-006

» w = 1.5; x = SOR(A, b, x0, w, tol, 100); i x1 x2 x3 .... 1.0000 -0.7500 9.2812 9.5312 2.0000 6.6797 -3.7178 9.4092 3.0000 -1.9556 12.4964 4.0732 4.0000 6.4414 -5.0572 11.9893 5.0000 -1.3712 12.5087 3.1484 6.0000 5.8070 -4.3497 12.0552 7.0000 -0.7639 11.4718 3.4949 8.0000 5.2445 -3.1985 11.5303 9.0000 -0.2478 10.3155 4.0800 10.0000 4.7722 -2.0890 10.9426 11.0000 0.1840 9.2750 4.6437 12.0000 4.3775 -1.1246 10.4141 13.0000 0.5448 8.3869 5.1335 14.0000 4.0477 -0.3097 9.9631 15.0000 0.8462 7.6404 5.5473 ……… 20.0000 3.3500 1.4220 9.0016 ……… 30.0000 2.7716 2.8587 8.2035 ……… 50.0000 2.4406 3.6808 7.7468 ……… 100.0000 2.3757 3.8419 7.6573

SOR method did not converge

SOR with SOR with = 1.5 = 1.5

Diverged !!

Page 30: Chapter 12 Iterative Methods for System of Equations

CVEN 302-501CVEN 302-501Homework No. 8Homework No. 8

Chapter 12Prob. 12.4 & 12.5 (Hand

calculation and check the results using the programs)

You do it but do not hand in. The You do it but do not hand in. The solution will be posted on the net. solution will be posted on the net.

Page 31: Chapter 12 Iterative Methods for System of Equations

Nonlinear SystemsNonlinear SystemsSimultaneous nonlinear equations

Example

0xxxxf

0xxxxf

0xxxxf

0xxxxf

n321n

n3213

n3212

n3211

),,,,(

),,,,(

),,,,(

),,,,(

4xx2x5

8xx7x5xx2

7x4x2x

2321

232221

322

21

Page 32: Chapter 12 Iterative Methods for System of Equations

Two Nonlinear FunctionsTwo Nonlinear Functions

Circle x2 + y2 = r2

Ellipse (x/a)2 + (y/b)2 = 1

f(x,y)=0g(x,y)=0 Solution

depends on initial guesses

Page 33: Chapter 12 Iterative Methods for System of Equations

function [x1,y1,x2,y2]=curves(r,a,b,theta)

% Circle with radius A

x1=r*cos(theta); y1=r*sin(theta);

% Ellipse with major and minor axes (a,b)

x2=a*cos(theta); y2=b*sin(theta);

» r=2; a=3; b=1; theta=0:0.02*pi:2*pi;

» [x1,y1,x2,y2]=curves(2,3,1,theta);

» H=plot(x1,y1,'r',x2,y2,'b');

» set(H,'LineWidth',3.0); axis equal;

Page 34: Chapter 12 Iterative Methods for System of Equations

Newton-Raphson MethodNewton-Raphson MethodOne nonlinear equation (Ch.6)

Two nonlinear equations (Taylor-series)

)(

)(

)()()()(

i

ii1i

ii1ii1i

xf

xfxx

xfxxxfxf

2

i2i21i2

1

i2i11i1i21i2

2

i1i21i2

1

i1i11i1i11i1

x

fxx

x

fxxff

x

fxx

x

fxxff

,,,

,,,,,

,,,

,,,,,

)()(

)()(

Page 35: Chapter 12 Iterative Methods for System of Equations

Intersection of Two CurvesIntersection of Two Curves

Two roots: f1(x1,x2) = 0 , f2 (x1,x2) = 0

Alternatively

2

i2i2

1

i2i1i21i2

2

i21i1

1

i2

2

i1i2

1

i1i1i11i2

2

i11i1

1

i1

1i2

1i1

x

fx

x

fxfx

x

fx

x

f

x

fx

x

fxfx

x

fx

x

f

0f

0f

,,

,,,,

,,

,

,,

,,,,

,,

,

,

,

f

f

xx

xx

x

f

x

fx

f

x

f

i2

i1

i21i2

i11i1

2

i2

1

i2

2

i1

1

i1

.

,

,,

,,

,,

,,[J]{x} = { f }

Jacobian matrix

Page 36: Chapter 12 Iterative Methods for System of Equations

Intersection of Two CurvesIntersection of Two Curves

Intersection of a circle and a parabola

0xxxxf

01xxxxf or

0yxyxg

01yxyxf

221212

22

21211

2

22

),(

),(

),(

),(

Page 37: Chapter 12 Iterative Methods for System of Equations

1x2

x2x2

x

f

x

fx

f

x

f

xxxxf

1xxxxf

1

21

2

2

1

2

2

1

1

1

221212

22

21211

),(

),(

i2

i1

i2

i1

i1

i2i1

f

f

x

x

1x2

x2x2xJ

,

,

,

,

,

,,}]{[

Intersection of Two CurvesIntersection of Two Curves

i21i2

i11i1oldnew

i2

i1

xy

xxxx

x

xx

,,

,,

,

,

Solve for xnew

Page 38: Chapter 12 Iterative Methods for System of Equations

function [x,y,z]=ellipse(a,b,c,imax,jmax)for i=1:imax+1 theta=2*pi*(i-1)/imax; for j=1:jmax+1 phi=2*pi*(j-1)/jmax; x(i,j)=a*cos(theta); y(i,j)=b*sin(theta)*cos(phi); z(i,j)=c*sin(theta)*sin(phi); endend

» a=3; b=2; c=1; imax=50; jmax=50;

» [x,y,z]=ellipse(a,b,c,imax,jmax);

» surf(x,y,z); axis equal;

» print -djpeg100 ellipse.jpg

Page 39: Chapter 12 Iterative Methods for System of Equations

function [x,y,z]=parabola(a,b,c,imax,jmax)% z=a*x^2+b*y^2+cfor i=1:imax+1 xi=-2+4*(i-1)/imax; for j=1:jmax eta=-2+4*(j-1)/jmax; x(i,j)=xi; y(i,j)=eta; z(i,j)=a*x(i,j)^2+b*y(i,j)^2+c; endend

» a=0.5; b=-1; c=1; imax=50; jmax=50;

» [x2,y2,z2]=parabola(a,b,c,imax,jmax);

» surf(x2,y2,z2); axis equal;

» a=3; b=2; c=1; imax=50; jmax=50;

» [x1,y1,z1]=ellipse(a,b,c,imax,jmax);

» surf(x1,y1,z1); hold on; surf(x2,y2,z2); axis equal;

» print -djpeg100 parabola.jpg

Parabolic or Hyperbolic Surfaces

Page 40: Chapter 12 Iterative Methods for System of Equations

Intersection of two nonlinear surfacesIntersection of two nonlinear surfaces

Infinite many

solutions

Page 41: Chapter 12 Iterative Methods for System of Equations

Intersection of three nonlinear surfacesIntersection of three nonlinear surfaces» [x1,y1,z1]=ellipse(2,2,2,50,50);» [x2,y2,z2]=ellipse(3,2,1,50,50);» [x3,y3,z3]=parabola(-0.5,0.5,-0.5,30,30);» surf(x1,y1,z1); hold on; surf(x2,y2,z2); surf(x3,y3,z3);» axis equal; view (-30,60);» print -djpeg100 surf3.jpg

Page 42: Chapter 12 Iterative Methods for System of Equations

Newton-Raphson MethodNewton-Raphson Method

)(

)(

)(

)(

),....,,,(

),....,,,(

),....,,,(

),....,,,(

xf

xf

xf

xf

)x(F

0xxxxf

0xxxxf

0xxxxf

0xxxxf

n

3

2

1

n321n

n3213

n3212

n3211

n32 1 x x xxx , 0xF

)(

n nonlinear equations in n unknowns

Page 43: Chapter 12 Iterative Methods for System of Equations

Jacobian (matrix of partial derivatives)

Newton’s iteration (without inversion)

Newton-Raphson MethodNewton-Raphson Method

1 1 1 1

1 2 3

2 2 2 2

1 2 3

3 3 3 3

1 2 3

1 2 3

( )

n

n

n

n n n n

n

f f f f

x x x x

f f f f

x x x x

J x f f f f

x x x x

f f f f

x x x x

oldnewoldold xxxy xFyxJ

);()(

Page 44: Chapter 12 Iterative Methods for System of Equations

For a single equation with one variable

Newton’s iteration

Newton-Raphson MethodNewton-Raphson Method

)()( xfdx

dfxJ

)(

)()(

old

oldoldold

1oldnew xf

xfxf xJxx

)(

)(

i

ii1i xf

xfxx

Page 45: Chapter 12 Iterative Methods for System of Equations

function x = Newton_sys(F, JF, x0, tol, maxit)

% Solve the nonlinear system F(x) = 0 using Newton's method% Vectors x and x0 are row vectors (for display purposes)% function F returns a column vector, [f1(x), ..fn(x)]'% stop if norm of change in solution vector is less than tol% solve JF(x) y = - F(x) using Matlab's "backslash operator"% y = -feval(JF, xold) \ feval(F, xold);% the next approximate solution is x_new = xold + y';

xold = x0;disp([0 xold ]);iter = 1;while (iter <= maxit) y= - feval(JF, xold) \ feval(F, xold); xnew = xold + y'; dif = norm(xnew - xold); disp([iter xnew dif]); if dif <= tol x = xnew; disp('Newton method has converged') return; else xold = xnew; end iter = iter + 1;enddisp('Newton method did not converge')x=xnew;

Page 46: Chapter 12 Iterative Methods for System of Equations

function df = ex11_1_j(x)

df = [2*x(1) 2*x(2) 2*x(1) -1 ] ;

function f = ex11_1(x)

f = [(x(1)^2 + x(2)^2 -1) (x(1)^2 - x(2)) ];

» x0=[0.5 0.5]; tol=1.e-6; maxit=100;» x=Newton_sys('ex11_1','ex11_1_j',x0,tol,maxit);

0 0.5000 0.5000 1.0000 0.8750 0.6250 0.3953 2.0000 0.7907 0.6181 0.0846 3.0000 0.7862 0.6180 0.0045 4.0000 0.7862 0.6180 0.0000 5.0000 0.7862 0.6180 0.0000Newton method has converged

Use x0 = [0.5 0.5] as initial estimates

Intersection of Circle and ParabolaIntersection of Circle and Parabola

Page 47: Chapter 12 Iterative Methods for System of Equations

Intersection of Three SurfacesIntersection of Three Surfaces

Solve the nonlinear system

Jacobian

0xx3xxxxf

09x2xxxxf

014xxxxxxf

or

0zy3xzyxh

09y2xzyxg

014zyxzyxf

23

2213213

22

213212

23

22

213211

22

22

222

),(

),(

),(

),,(

),,(

),,(

,

,

,

x2x61

0x4x2

x2x2x2

x

f

x

f

x

fx

f

x

f

x

fx

f

x

f

x

f

J

32

21

321

3

3

2

3

1

3

3

2

2

2

1

2

3

1

2

1

1

1

][

Page 48: Chapter 12 Iterative Methods for System of Equations

Newton-Raphson MethodNewton-Raphson MethodSolve the nonlinear system

MATLAB function ( y = J-1F )

3

2

1

old

old

old

new

new

new

3

2

1

3

2

1

32

21

321

x

x

x

z

y

x

z

y

x

f

f

f

x

x

x

x2x61

0x4x2

x2x2x2

y = feval(JF,xold) \ feval(F, xold)

Page 49: Chapter 12 Iterative Methods for System of Equations

» x0=[1 1 1]; es=1.e-6; maxit=100;

» x=Newton_sys(‘ex11_2',‘ex11_2_j',x0,es,maxit);

0 1 1 1

1.0000 1.6667 2.1667 4.6667 3.9051

2.0000 1.5641 1.8407 3.2207 1.4858

3.0000 1.5616 1.8115 2.8959 0.3261

4.0000 1.5616 1.8113 2.8777 0.0182

5.0000 1.5616 1.8113 2.8776 0.0001

6.0000 1.5616 1.8113 2.8776 0.0000

Newton method has converged

function f = ex11_2(x)% Intersection of three surfaces

f = [ (x(1)^2 + x(2)^2 + x(3)^2 - 14) (x(1)^2 + 2*x(2)^2 - 9) (x(1) - 3*x(2)^2 + x(3)^2) ];

function df = ex11_2_j(x)% Jacobian matrixdf = [ 2*x(1) 2*x(2) 2*x(3) 2*x(1) 4*x(2) 0 1 -6*x(2) 2*x(3) ] ;

Intersection of Three SurfacesIntersection of Three Surfaces

Page 50: Chapter 12 Iterative Methods for System of Equations

No need to compute partial derivatives

Fixed-Point IterationFixed-Point Iteration

)x,....,x,x,x(gx

)x,....,x,x,x(gx

)x,....,x,x,x(gx

)x,....,x,x,x(gx

0)x,....,x,x,x(f

0)x,....,x,x,x(f

0)x,....,x,x,x(f

0)x,....,x,x,x(f

n321nn

n32133

n32122

n32111

n321n

n3213

n3212

n3211

1K ;n

K

x

g

j

i Convergence

Theorem

Page 51: Chapter 12 Iterative Methods for System of Equations

Example1: Fixed-PointExample1: Fixed-Point

Solve the nonlinear system

Rearrange (initial guess: x = y = z = 2)

075x40xx)x,x,x(f

050xx20x)x,x,x(f

0200xxx50x)x,x,x(f

322

213213

232

213212

23

221

213211

/40)75xx()x,x,x(gx

/20)xx50()x,x,x(gx

/50)xxx200()x,x,x(gx

22

2132133

23

2132122

23

22

2132111

Page 52: Chapter 12 Iterative Methods for System of Equations

function x = fixed_pt_sys(G, x0, es, maxit)% Solve the nonlinear system x = G(x) using fixed-point method% Vectors x and x0 are row vectors (for display purposes)% function G returns a column vector, [g1(x), ..gn(x)]'% stop if norm of change in solution vector is less than es% y = feval(G,xold); the next approximate solution is xnew = y';

disp([0 x0 ]); %display initial estimatexold = x0;iter = 1;while (iter <= maxit) y = feval(G, xold); xnew = y'; dif = norm(xnew - xold); disp([iter xnew dif]); if dif <= es x = xnew; disp('Fixed-point iteration has converged') return; else xold = xnew; end iter = iter + 1;enddisp('Fixed-point iteration did not converge')x=xnew;

Page 53: Chapter 12 Iterative Methods for System of Equations

» x0=[0 0 0]; es=1.e-6; maxit=100;» x=fixed_pt_sys('example1', x0, es, maxit);

0 0 0 0 1.0000 4.0000 2.5000 -1.8750 5.0760 2.0000 3.4847 1.5242 -1.3188 1.2358 3.0000 3.6759 1.8059 -1.5133 0.3921 4.0000 3.6187 1.7099 -1.4557 0.1257 5.0000 3.6372 1.7393 -1.4745 0.0395 6.0000 3.6314 1.7298 -1.4686 0.0126 7.0000 3.6333 1.7328 -1.4705 0.0040 8.0000 3.6327 1.7318 -1.4699 0.0013 9.0000 3.6329 1.7321 -1.4701 0.0004 10.0000 3.6328 1.7321 -1.4700 0.0001 11.0000 3.6328 1.7321 -1.4701 0.0000 12.0000 3.6328 1.7321 -1.4701 0.0000 13.0000 3.6328 1.7321 -1.4701 0.0000 14.0000 3.6328 1.7321 -1.4701 0.0000 15.0000 3.6328 1.7321 -1.4701 0.0000

Fixed-point iteration has converged

function G = example1(x)

G = [ (-0.02*x(1)^2 - 0.02*x(2)^2 - 0.02*x(3)^2 + 4)

(-0.05*x(1)^2 - 0.05*x(3)^2 + 2.5)

(0.025*x(1)^2 + 0.025*x(2)^2 -1.875) ];

Page 54: Chapter 12 Iterative Methods for System of Equations

Example 2: Fixed-PointExample 2: Fixed-Point

Solve the nonlinear system

Rearrange (initial guess: x = 0, y = 0, z > 0)

011xxxxxf

047x9xxxxf

036x9x4xxxxf

3213213

22

23212

23

22

213211

1

),,(

),,(

),,(

3x4x36xxxgx

3x47xxxgx

x11xxxgx

22

2132133

2132122

332111

/),,(

/),,(

/),,(

Page 55: Chapter 12 Iterative Methods for System of Equations

function G = example2(x)G = [ (sqrt(11/x(3))) (sqrt(47 - x(1)^2) / 3 ) (sqrt(36 - x(1)^2 - 4*x(2)^2) / 3 ) ];

» x0=[0 0 10]; es=0.0001; maxit=500;» x=fixed_pt_sys(‘example2',x0,es,maxit);

0 0 0 10 1.0000 1.0488 2.2852 2.0000 8.3858 2.0000 2.3452 2.2583 1.2477 1.4991 3.0000 2.9692 2.1473 1.0593 0.6612 4.0000 3.2224 2.0598 0.9854 0.2779 5.0000 3.3411 2.0170 0.9801 0.1263 6.0000 3.3501 1.9955 0.9754 0.0238 7.0000 3.3581 1.9938 0.9916 0.0181 8.0000 3.3307 1.9923 0.9901 0.0275 9.0000 3.3332 1.9974 1.0017 0.0129 10.0000 3.3139 1.9969 0.9962 0.0201 11.0000 3.3230 2.0005 1.0037 0.0124 12.0000 3.3105 1.9988 0.9972 0.0142 13.0000 3.3213 2.0011 1.0033 0.0126 14.0000 3.3112 1.9991 0.9973 0.0120 15.0000 3.3212 2.0010 1.0028 0.0116 16.0000 3.3120 1.9992 0.9974 0.0107 17.0000 3.3209 2.0008 1.0024 0.0103 18.0000 3.3126 1.9992 0.9977 0.0097 19.0000 3.3205 2.0007 1.0022 0.0092 20.0000 3.3130 1.9993 0.9979 0.0087 ... 50.0000 3.3159 1.9999 0.9996 0.0017 ... 102.0000 3.3166 2.0000 1.0000 0.0001 103.0000 3.3167 2.0000 1.0000 0.0001

Fixed-point iteration has converged