Chapter 6

Nonlinear

6.1 The Problem of Nonlinear Root-finding

In this module we consider the problem of using numerical techniques to find the roots of nonlinear

x = 0 equations, f . Initially we examine the case where the nonlinear equations are a scalar

function of a single independent variable, x. Later, we shall consider the more difficult problem

n f x= 0

where we have a system of n nonlinear equations in independent variables, .

x = 0 Since the roots of a nonlinear , f , cannot in general be expressed in closed form, we must use approximate methods to solve the problem. Usually, iterative techniques are

used to start from an initial approximation to a root, and produce a sequence of approximations



0 1 2

x ;x ;x ;::: ;

which converge toward a root. Convergence to a root is usually possible provided that the function

x f is sufficiently smooth and the initial approximation is close enough to the root.

6.2 Rate of Convergence

Let



0 1 2

x ;x ;x ;:::

c Department of Engineering Science, University of Auckland, New Zealand. All rights reserved. July 11, 2002

70 NONLINEAR EQUATIONS

k  k 

 = x p be a sequence which converges to a root ,andlet . If there exists a number and

a non-zero constant c such that

k +1



lim = c;

p (6.1)

k 

k !1

j j

p = 1; 2; 3 then p is called the order of convergence of the sequence. For the order is said to be linear, quadratic and cubic respectively.

6.3 Termination Criteria

Since numerical computations are performed using floating point arithmetic, there will always be

a finite precision to which a function can be evaluated. Let  denote the limiting accuracy of the nonlinear function near a root. This limiting accuracy of the function imposes a limit on the

accuracy, , of the root. The accuracy to which the root may be found is given by:



: =

 (6.2)

0

jf  j

This is the best error bound for any root finding method. Note that  is large when the first

0

f  j of the function at the root, j , is small. In this case the problem of finding the root is ill-

conditioned. This is shown graphically in Figure 6.1.

f x

f x  

2 2

1 2

2

1

2

2

x

 

0 1

large 2 small

f   1 ill-conditioned well-conditioned

FIGURE 6.1:

When the sequence



0 1 2

x ;x ;x ;::: ;

k  k 1 k 

x x   converges to the root, , then the differences x will decrease until .

c Department of Engineering Science, University of Auckland, New Zealand. All rights reserved. July 11, 2002 6.4 71

With further iterations, rounding errors will dominate and the differences will vary irregularly.

k 

The iterations should be terminated and x be accepted as the estimate for the root when the

following two conditions are satisfied simultaneously:

k +1 k  k  k 1

x x  x

1. x and (6.3)

k  k 1

x x

:

2. < (6.4)

k 

1+jx j

k 

x

 is some coarse tolerance to prevent the iterations from being terminated before is close to ,

k  k 1

x

i.e. before the step size x becomes “small”. The condition (6.4) is able to test the relative

k 

x 1 offset when is much larger than 1 andmuchsmallerthan . In practice, these conditions are used in conjunction with the condition that the number of iterations not exceed some user defined limit.

6.4 Bisection Method



0 1

f x ;x

Suppose that is continuous on an interval x . A root is bracketed on the interval

  

0 1 0 1

f f ;x x x x if and have opposite sign.

Let

1 0

x x

2 0

= x +

x (6.5)

2



0 1 ;x

be the mid-point of the interval x . Three mutually exclusive possibilities exist:



2

f x =0

 if then the root has been found;

  

2 0 2 1

 f x f x ;x

if has the same sign as then the root is in the interval x ;

  

0 2 2 1

x ;x f x f x  if has the same sign as then the root is in the interval .

In the last two cases, the size of the interval bracketing the root has decreased by a factor of two. The next iteration is performed by evaluating the function at the mid-point of the new interval.

After k iterations the size of the interval bracketing the root has decreased to:

1 0

x x

k 2

c Department of Engineering Science, University of Auckland, New Zealand. All rights reserved. July 11, 2002 72 NONLINEAR EQUATIONS

The process is shown graphically in Figure 6.2. The bisection method is guaranteed to converge to a root. If the initial interval brackets more than one root, then the bisection method will find one

of them.

f x

1

x

0

x

x

2

x

3

x

4

x

5 x

FIGURE 6.2:

Since the interval size is reduced by a factor of two at each iteration, it is simple to calculate in

k 

advance the number of iterations, , required to achieve a given tolerance, 0 , in the solution:

1 0

x x

k = :

log2

 0

The bisection method has a relatively slow linear convergence.

6.5 Secant Method

x The bisection method uses no information about the function values, f , apart from whether

they are positive or negative at certain values of x. Suppose that

 

k 1 k 

; < f x f x

k  k 1 x Then we would expect the root to lie closer to x than . Instead of choosing the new estimate

to lie at the midpoint of the current interval, as is the case with the bisection method, the secant



k 1 k 1

x ;f x

method chooses the x-intercept of the to the curve, the line through



k  k 

;f x f x and x . This places the new estimate closer to the endpoint for which has the

smallest absolute value. The new estimate is:

 

k  k  k 1

f x x x

k +1 k 

x = x

: (6.6)

k  k 1

f x  f x 

c Department of Engineering Science, University of Auckland, New Zealand. All rights reserved. July 11, 2002 6.6 REGULA FALSI 73

Note that the secant method requires two initial function evaluations but only one new function

evaluation is made at each iteration. The secant method is shown graphically in Figure 6.3.

f x

0

1

2

x

x

x

3

x x

FIGURE 6.3:

The secant method does not have the root bracketing property of the bisection method since

k +1 k 1 k 

x x the new estimate, x , of the root need not lie within the bounds defined by and .As a consequence, the secant method does not always converge, but when it does so it usually does so faster than the bisection method. It can be shown that the order of convergence of the secant

method is:

p

1+ 5

 1:618: 2

6.6 Regula Falsi

Regula falsi is a variant of the secant method. The difference between the secant method and

regula falsi lies in the choice of points used to form the secant. While the secant method uses



k 1 k 1

;f x

the two most recent function evaluations to form the secant line through x and



k  k 

x x

;f , regula falsi forms the secant line through the most recent points that bracket the 0 root. The regula falsi steps are shown graphically in Figure 6.4. In this example, the point x remains active for many steps. The advantage of regula falsi is that like the bisection method, it is always convergent. How- ever, like the bisection method, it has only linear convergence. Examples where the regula falsi method is slow to converge are not hard to find. One example is shown in Figure 6.5.

c Department of Engineering Science, University of Auckland, New Zealand. All rights reserved. July 11, 2002

74 NONLINEAR EQUATIONS

f x

0

1

x

x

3

2

x

x x

FIGURE 6.4:

f x

3

x

0

x

2 1

x

x x

FIGURE 6.5:

c Department of Engineering Science, University of Auckland, New Zealand. All rights reserved. July 11, 2002 6.7 NEWTON’S METHOD 75

6.7 Newton’s Method

The methods discussed so far have required only function values to compute the new estimate of the root. Newton’s method requires that both the function value and the first derivative be evaluated. Geometrically, Newton’s method proceeds by extending the tangent line to the function

at the current point until it crosses the x-axis. The new estimate of the root is taken as the abscissa

of the zero crossing. Newton’s method is defined by the following iteration:



k 

f x

k +1 k 

x = x

: (6.7)

0 k 

f x 

The update is shown graphically in Figure 6.6.

f x

2

1 0

x

x x x

FIGURE 6.6:

Newton’s method may be derived from the Taylor series expansion of the function:

2

x

0 00

+ ::: x +x=f x+f xx + f x

f (6.8)

2 x

For a smooth function and small values of  , the function is approximated well by the first two

f  x

f x +x=0 x =

terms. Thus implies that 0 . Far from a root the higher order terms are

f x significant and Newton’s method can give highly inaccurate corrections. In such cases the Newton iterations may never converge to a root. In order to achieve convergence the starting values must be reasonably close to a root. An example of divergence using Newton’s method is given in Figure 6.7. Newton’s method exhibits quadratic convergence. Thus, near a root the number of significant digits doubles with each iteration. The strong convergence makes Newton’s method attractive in cases where the can be evaluated efficiently and the derivative is continuous and non- zero in the neighbourhood of the root (as is the case with multiple roots). Whether the secant method should be used in preference to Newton’s method depends upon the relative work required to compute the first derivative of the function. If the work required to

c Department of Engineering Science, University of Auckland, New Zealand. All rights reserved. July 11, 2002

76 NONLINEAR EQUATIONS

f x

0

1

x

x x

FIGURE 6.7:

:44 evaluate the first derivative is greater than 0 times the work required to evaluate the function, then use the secant method, otherwise use Newton’s method. It is easy to circumvent the poor global convergence properties of Newton’s method by com- bining it with the bisection method. This hybrid method uses a bisection step whenever the Newton

method takes the solution outside the bisection bracket. Global convergence is thus assured while

k  k +1 x retaining quadratic convergence near the root. Line searches of the Newton step from x to are another method for achieving better global convergence properties of Newton’s method.

6.8 Examples

In the following examples, the bisection, secant, regula falsi and Newton’s methods are applied to

2

f x = x 1 [0; 3] x x R

find the root of the non- between . L and are the left and 

right bracketing values and xnew is the new value determined at each iteration. is the distance n from the true solution, f is the number of function evaluations required at each iteration. The

bisection method is terminated when conditions (6.3) and (6.4) are simultaneously satisfied for

4

 10 =1 . The remaining methods determine the solution to the same level of accuracy as the bisection method. The examples show the linear convergence rate of the bisection and regula falsi methods, the better than linear convergence rate of the secant method and the quadratic convergence rate of Newton’s method. It is also seen that although Newton’s method converges in 5 iterations, 5 function and 5 derivative evaluations, to give a total of 10 evaluations, are required. This contrasts to the secant method where for the 8 iterations, 9 function evaluations are made.

c Department of Engineering Science, University of Auckland, New Zealand. All rights reserved. July 11, 2002 6.8 EXAMPLES 77

Bisection Method - f(x) = x2-1

k+1 k k k-1 k k-1 k k xL xR xnew fL(x) fR(x) f(xnew) ε nf |x -x ||x-x | |x -x |/1+|x | 0 0.000000 3.000000 1.500000 -1.000000 8.000000 1.250000 0.500000 3 1 0.000000 1.500000 0.750000 -1.000000 1.250000 -0.437500 0.250000 1 2 0.750000 1.500000 1.125000 -0.437500 1.250000 0.265625 0.125000 1 0.375000 0.750000 0.428571 3 0.750000 1.125000 0.937500 -0.437500 0.265625 -0.121094 0.062500 1 0.187500 0.375000 0.176471 4 0.937500 1.125000 1.031250 -0.121094 0.265625 0.063477 0.031250 1 0.093750 0.187500 0.096774 5 0.937500 1.031250 0.984375 -0.121094 0.063477 -0.031006 0.015625 1 0.046875 0.093750 0.046154 6 0.984375 1.031250 1.007813 -0.031006 0.063477 0.015686 0.007813 1 0.023438 0.046875 0.023622 7 0.984375 1.007813 0.996094 -0.031006 0.015686 -0.007797 0.003906 1 0.011719 0.023438 0.011673 8 0.996094 1.007813 1.001953 -0.007797 0.015686 0.003910 0.001953 1 0.005859 0.011719 0.005871 9 0.996094 1.001953 0.999023 -0.007797 0.003910 -0.001952 0.000977 1 0.002930 0.005859 0.002927 10 0.999023 1.001953 1.000488 -0.001952 0.003910 0.000977 0.000488 1 0.001465 0.002930 0.001466 11 0.999023 1.000488 0.999756 -0.001952 0.000977 -0.000488 0.000244 1 0.000732 0.001465 0.000732 12 0.999756 1.000488 1.000122 -0.000488 0.000977 0.000244 0.000122 1 0.000366 0.000732 0.000366 13 0.999756 1.000122 0.999939 -0.000488 0.000244 -0.000122 0.000061 1 0.000183 0.000366 0.000183 14 0.999939 1.000122 1.000031 0.000031 0.000092 0.000183 0.000092 16

2 Secant Method - f(x) = x -1 2 k k-1 k f(x) = x -1 k x1 x2 f(x1) f(x2) ε nf |x -x |/1+|x |

0 0.000000 3.000000 -1.000000 8.000000 2.000000 2 f(x) 20 1 3.000000 0.333333 8.000000 -0.888889 0.666667 1 2.000000 2 0.333333 0.600000 -0.888889 -0.640000 0.400000 1 0.166667 10 3 0.600000 1.285714 -0.640000 0.653061 0.285714 1 0.300000 4 1.285714 0.939394 0.653061 -0.117539 0.060606 1 0.178571 0 5 0.939394 0.992218 -0.117539 -0.015504 0.007782 1 0.026515 -1 -0.5 3E-16 0.5 1 1.5 2 2.5 3 3.5 4 6 0.992218 1.000244 -0.015504 0.000488 0.000244 1 0.004013 x 7 1.000244 0.999999 0.000488 -0.000002 0.000001 1 0.000123 -10 8 0.999999 1.000000 0.000000 0.000000 9

Regula Falsi Method - f(x) = x2-1 k k-1 k k x1 x2 f(x1) f(x2) xnew f(xnew) ε nf |x -x |/1+|x | 0 0.000000 3.000000 -1.000000 8.000000 0.333333 -0.888889 0.666667 3 1 0.333333 3.000000 -0.888889 8.000000 0.600000 -0.640000 0.400000 1 0.166667 2 0.600000 3.000000 -0.640000 8.000000 0.777778 -0.395062 0.222222 1 0.100000 3 0.777778 3.000000 -0.395062 8.000000 0.882353 -0.221453 0.117647 1 0.055556 4 0.882353 3.000000 -0.221453 8.000000 0.939394 -0.117539 0.060606 1 0.029412 5 0.939394 3.000000 -0.117539 8.000000 0.969231 -0.060592 0.030769 1 0.015152 6 0.969231 3.000000 -0.060592 8.000000 0.984496 -0.030767 0.015504 1 0.007692 7 0.984496 3.000000 -0.030767 8.000000 0.992218 -0.015504 0.007782 1 0.003876 8 0.992218 3.000000 -0.015504 8.000000 0.996101 -0.007782 0.003899 1 0.001946 9 0.996101 3.000000 -0.007782 8.000000 0.998049 -0.003899 0.001951 1 0.000975 10 0.998049 3.000000 -0.003899 8.000000 0.999024 -0.001951 0.000976 1 0.000488 11 0.999024 3.000000 -0.001951 8.000000 0.999512 -0.000976 0.000488 1 0.000244 12 0.999512 3.000000 -0.000976 8.000000 0.999756 -0.000488 0.000244 1 0.000122 13 0.999756 3.000000 -0.000488 8.000000 0.999878 0.000122 0.000061 15

Newton's Method - f(x) = x2-1; f'(x) = 2x k k-1 k k x f(x) f'(x) ε nf nf' |x -x |/1+|x | 0 3.000000 8.000000 6.000000 2.000000 1 1 1 1.666667 1.777778 3.333333 0.666667 1 1 0.500000 2 1.133333 0.284444 2.266667 0.133333 1 1 0.250000 3 1.007843 0.015748 2.015686 0.007843 1 1 0.062500 4 1.000031 0.000061 2.000061 0.000031 1 1 0.003906 5 1.000000 0.000000 0.000015 55

c Department of Engineering Science, University of Auckland, New Zealand. All rights reserved. July 11, 2002 78 NONLINEAR EQUATIONS

6.9 Laguerre’s Method

In the previous sections we have investigated methods for finding the roots of general functions. These techniques may sometimes work for finding roots of polynomials, but often problems arise because of multiple roots or complex roots. Better methods are available for nonlinear functions with these types of roots. One such technique is Laguerre’s method. th

Consider the n order polynomial:

n

P x=x x x x  :::x x :

2 n 1 (6.9)

Taking the logarithm of both sides gives:

jP xj = jx x j + jx x j + ::: + jx x j :

1 2 n ln n ln ln ln (6.10)

Let:

d jP xj

ln n =

G (6.11)

dx

1 1 1

+ + ::: +

= (6.12)

x x x x x x

1 2 n

0

P x n

= (6.13)

P x n

and

2

d jP xj

ln n

=

H (6.14)

2

dx

1 1 1

+ + ::: +

= (6.15)

2 2 2

x x  x x  x x 

1 2 n

2

0 00

P x P x

n n

:

= (6.16)

P x P x

n n

x

If we make the assumption that the root 1 is located a distance from our current estimate,

k 

x , and all other roots are located at a distance , then:

k 

x x =

1 (6.17)

k 

x x = for i =2; 3;::: ;n:

i (6.18)

c Department of Engineering Science, University of Auckland, New Zealand. All rights reserved. July 11, 2002 6.9 LAGUERRE’S METHOD 79

Equations (6.13) and (6.16) can now be expressed as:

1 n 1

G =

+ (6.19)

1 n 1

H = :

+ (6.20)

2 2

Solving for gives:

n

p =

(6.21)

2

G  n 1 nH G  where the sign should be taken to yield the largest magnitude for the denominator. The new esti-

mate of the root is obtained from the old using the update:

k +1 k 

= x : x (6.22)

In general, will be complex.

  

0 00 k  k  k 

P P P x x x

Laguerre’s method requires that n , and be computed at each step.

n n The method is cubic in its convergence for real or complex simple roots. Laguerre’s method will converge to all types of roots of polynomials, real, complex, single or multiple. It requires complex arithmetic even when converging to a real root. However, for polynomials with all real roots, it is guaranteed to converge to a root from any starting point.

th

x n P x n

Afteraroot, 1 ,ofthe order polynomial, , has been found, the polynomial should

x x  n 1 be divided by the quotient, 1 , to yield an order polynomial. This process is called deflation. It saves computation when estimating further roots and ensures that subsequent iterations do not converge to roots already found.

6.9.1 Example

Following is a simple example that illustrates the use of Laguerre’s method. Consider the third

order polynomial:

2

P x=x 4x +3

2

0

P x=2x 4

2

00

P x=2 2

c Department of Engineering Science, University of Auckland, New Zealand. All rights reserved. July 11, 2002 80 NONLINEAR EQUATIONS

1. Let the initial estimate of the first root be:

0

x =0:5 1

then

0

2x 4

1

= 2:4 G =

2

0 0

4x +3 x

1 1

2

2

H = G =4:16

2

0 0

4x +3 x

1 1

2

p

= 0:5 = 4

(choosing as the largest denominator)

2

G  2 12H G 

The first root is then:

1 0

x = x =0:5 0:5 = 1:

P x 1 x =3

1 2 2. The second root is found by dividing 2 by . The trivial result is that .

6.9.2 Horner’s method for evaluating a polynomial and its derivatives

2 n

P x = a + a x + a x + ::: + a x

0 1 2 n The polynomial n should not be calculated by evaluating

the powers of x individually. It is much more efficient to calculate the polynomial using Horner’s

P x = a + x a + x a + ::: + xa 

0 1 2 n method by noting that n . Using this approach the poly- nomial value and the first and second derivatives may be evaluated efficiently using the following

:

p  a ;

n

0

p  0:0;

00

p  0:0;

n 1 :::0

for i in loop

00 00 0

p  x  p + p ;

0 0

p  x  p + p;

p  x  p + a ; i

end loop;

c Department of Engineering Science, University of Auckland, New Zealand. All rights reserved. July 11, 2002

6.9 LAGUERRE’S METHOD 81

00 00

p  2  p ;

2

n +3n=2

If the polynomial and its derivatives are evaluated using the individual powers of x,

2 2

n + n 2=2 n n 2=2

operations are required for the value,  for the first derivative and for

2

n +3n 4=2 6n +1 the second derivative, i.e. a total of 3 operations. Horner’s method requires

operations to evaluate the polynomial and both derivatives and thus requires less operations when 3 n> . If just the function evaluation is required, then Horner’s method will require less operations

for all n.

6.9.3 Example

Following is an example of how Horner’s method can be used to evaluate

2 3

P x = 1+2x 3x + x 3

and its derivatives.

0 00

=1 P =0 P =0

1. P , and .

00 0

=0+0 P = 0+1 P = x 3

2. P , and .

00 0

=0+1 P = x + x 3 P = xx 3+2

3. P , and .

00 0

= x +2x 3 P = x2x 3 + xx 3+2 P = xxx 3+2+1

4. P , and .

00

= 23x 3 5. P

6.9.4 Deflation

n x x 

Dividing a polynomial of order by a factor 1 may be performed using the following

algorithm:

r  a ;

n

a  0:0;

n

n 1 :::0

for i in loop

q  a ;

i

a  r ;

i

r  x  r + q ; 1

c Department of Engineering Science, University of Auckland, New Zealand. All rights reserved. July 11, 2002 82 NONLINEAR EQUATIONS

end loop;

a r

The coefficients of the new polynomial are stored in the array i , and the remainder in .

6.10 Systems of Nonlinear Equations n

Consider a general system of n nonlinear equations in unknowns:

f x ;x ;::: ;x = 0;i =1; 2;::: ;n:

i 1 2 n n Newton’s method can be generalised to n dimensions by examining Taylor’s series in dimen-

sions:

  

k +1 k 

k  k  0 k +1

x x + ::: x x + f x = f f

i i

ij

j j



0 k 

x n  n

where f is an matrix called the Jacobian, having elements:

ij

@f x

i

0

: x=

f (6.23)

ij

@x j

If these gradients are approximately calculated, the method is called a quasi-Newton method. One

f x x  f x + x 

j i j way to approximately form the gradients is to calculate i and and then

form the finite difference approximation:

f x + x  f x x 

i j i j

0

x 

f (6.24)

ij

2x j

th

x j

The vector j is a vector of zeros, except for a small perturbation in the position.



k +1

f n x =0

Setting i gives Newton’s formula in dimensions:

 

k +1 k 

k  0 k 

= f x f x x x

i (6.25)

ij

j j

or,



k +1

k  0 k 

x f x  = f

i (6.26)

ij

j

k +1 k +1 k 

 = x n

where x is the vector of updates. Equation (6.26) is a set of linear

j j j

k +1 

equations in n unknowns, . If the Jacobian is non-singular, then the system of linear equations j

c Department of Engineering Science, University of Auckland, New Zealand. All rights reserved. July 11, 2002 6.10 SYSTEMS OF NONLINEAR EQUATIONS 83

can be solved to provide the Newton update:

k +1 k  k +1

= x +  :

x (6.27)

j j j

Each step of Newton’s method requires the solution of a set of linear equations. For small n the

set of linear equations may be solved using LU decomposition. For large n, alternative iterative

methods may be required. As with the one-dimensional version, Newton’s method converges 0 quadratically if the initial estimate, x , is sufficiently close to a root. Newton’s method in multiple dimensions suffers from the same global convergence problems as its one-dimensional counterpart.

6.10.1 Example 1 y

Consider finding x and such that the following are true:

2 2

f x; y = x 2x + y 2y 2xy +1 = 0

1 (6.28)

2 2

f x; y = x +2x + y +2y +2xy +1 = 0

2 (6.29)

This is a contrived problem, but it serves to illustrate the application of Newton’s in multiple dimensions. Solving for the simultaneous roots of these equations is equivalent to finding the roots

of the single factored equation:

2 2

x; y = x + y +1 x y 1

f (6.30)

; 1 Inspection shows that this equation has the root 0 . The first step in applying Newton’s method is to determine the form of the Jacobian and the

right hand side function vector for calculating the update vector for each iteration. These are:

2 3

k  k  k  k 

@f x ;y  @f x ;y 

 "  "

1 1

k +1

k  k 

6 7

f x ;y  

x

1

@x @y

6 7

= (6.31)

k  k  k  k 

k +1

4 5

k  k 

@f x ;y  @f x ;y 

2 2

f x ;y  

y

2

@x @y

" "  " 

k +1

2 2

2x y 1 2y x 1  x +2x y +2y +2xy 1 x

= (6.32)

k +1

2 2

2x + y +1 2x + y +1  x 2x y 2y 2xy 1 y

c Department of Engineering Science, University of Auckland, New Zealand. All rights reserved. July 11, 2002 84 NONLINEAR EQUATIONS

The algorithm for solving this problem is:

k  0;

 >;

k  k 

x ;y ;

specify starting point: 

> k

while:  and

1

k +1 0

f ; f

 (LU factorisation and solution)

k +1

k +1 k 

x  x +  ;

k  k +1

  ;  

2 2

k  k +1;

end loop;  Where N is some specified maximum number of iterations and is some specified convergence

tolerance.

; 1 1; 3

Sequences of Newton steps converging toward the root 0 for the starting points ,

; 3 2; 0 2 and are shown in figures (6.8) and (6.9).

20

10

0 0

−0.5 f(x,y) −10 −1 −20 −1.5 −30 y −1 −2 −0.5 0 0.5 1 −2.5 1.5 x 2 2.5 −3 3

FIGURE 6.8: Sequence of Newton steps plotted on the surface defined by Equation (6.30).

c Department of Engineering Science, University of Auckland, New Zealand. All rights reserved. July 11, 2002 6.10 SYSTEMS OF NONLINEAR EQUATIONS 85

10

5 start at (−1,−3)

0

−5 f(x,y)

−10 start at (2,0)

−15 start at (2,−3)

−20 5 10 15 20 25 30 Number of iterations

FIGURE 6.9: Convergent behaviour of Equation (6.30) with Newton iteration.

6.10.2 Example 2

Newton’s method for finding roots in multiple dimensions becomes very useful when finding ap- proximate solutions to non-linear partial differential equations. Consider the diffusion equation in

one-dimension, where the diffusivity, D , is an exponential function of the concentration:

2

@ c @c

c

Ae =0

(6.33)

2

@t @x

This is a non-linear partial differential equation. th

A finite difference discretisation of this equation for the i node is:

n+1

n

n+1

n 1 c + c

i i

  

c c Ae

i

i

n n n n+1 n+1 n+1

1  c 2c + c + c 2c + c f =

i

i1 i i+1 i1 i i+1

2

t x

(6.34)

n+1 n+1 c

Notice that this is a non-linear equation whose roots are the unknown concentrations c ,

i1 i

n+1

m m m

and c . If there are discrete nodes in our problem, then there are equations and unknown

i+1 concentrations, so Newton’s method for multiple dimensions can be applied.

c Department of Engineering Science, University of Auckland, New Zealand. All rights reserved. July 11, 2002 86 NONLINEAR EQUATIONS

A row in the Jacobian for the internal node i will be:

 

@f @f @f

i i i

0  0

 (6.35)

n+1 n+1 n+1

@c @c @c

i1 i i+1

!  "

n+1

n

 

1 c + c

i

i

Ae 1

n+1

n n n

n

1 c + c

1  c 2c + c +

i

i

2

Ae

i1 i i+1

t x

0 

 

or 2

x

n+1 n+1 n+1

2

+ c 2 2c c

i+1 i i1

i

n+1

n

1 c + c

i

i

Ae

0

 (6.36)

2

x

f

The corresponding right hand side vector entry for the Newton update is i . Note that in contrast to the case of the linear diffusion equation, the system of discrete finite difference equations are now time varying and must be constructed and factorised for each time step.

If Dirichlet boundary conditions of 1 and 0 are applied at nodes 1 and n, respectively, then the

functions whose roots are to be found are:

n+1

f = c 1

1 (6.37)

1

n+1

f = c

n (6.38) n

The corresponding rows in the Jacobian will be:

h i

0  0

1 (6.39)

h i

 0 1

0 (6.40)

n+1

n+1

c c

The right hand side vector entries for the Newton update are 1 and , respectively.

1 n

n+1

Note that the unknown dependent variables for this non-linear problem are c . Let these

k 

th 

k c unknowns be referred to simply as c so that the Newton update becomes . The algorithm for solving this problem is similar to that of Example 1:

c Department of Engineering Science, University of Auckland, New Zealand. All rights reserved. July 11, 2002

6.10 SYSTEMS OF NONLINEAR EQUATIONS 87

0 T

for t in loop

k  0;

 >;

k  ;

specify starting point: c (This will be the solution from the previous time step)

> k

while:  and

1

k +1 0

f ; f

 (LU factorisation and solution)

k +1

k +1 k 

c  c +  ;

k +1 k 

  ;  

2 2

k  k +1;

end loop;

end loop;

x = 1 m t = 1 s = 1 Results for a problem of length 10 m with , and are shown in

Figure 6.10. The non-linear solutions were calculated using:

c

c=0:368e

D (6.41)

2 1 2

= 1m s c = 1kgm

The coefficient was chosen such that D at . The linear solutions were

2 1

=0:632 m s D c

calculated using D . This value was chosen as the integrated mean value of

2 2

= 0 kg m c = 1 kg m from c to . The variation of the diffusion coefficient with concentration is shown in Figure 6.11. The non-linear diffusion coefficient is smaller than the constant diffusion coefficient at lower concentrations. This is observed in the solutions, as the concentration profile for the non-linear diffusion does not advance as far as for constant diffusion over the same interval of time.

c Department of Engineering Science, University of Auckland, New Zealand. All rights reserved. July 11, 2002 88 NONLINEAR EQUATIONS

1 L 5s 0.5 NL 5s 0.9 L 10s NL 10s 0.45 L 50s 0.8 NL 50s 0.4

0.7 0.35

0.6 0.3

0.5 0.25 Concentration

0.4 Concentration 0.2

0.3 0.15

0.2 0.1

0.1 0.05 Linear Non−linear 0 0 0 1 2 3 4 5 6 7 8 9 10 0 10 20 30 40 50 60 70 80 90 100

x (m) Time (s) =5m (a) Profiles (b) Time history at x

FIGURE 6.10: Comparative solutions for constant diffusion and non-linear diffusion.

1.1 D=0.368exp(c) D=0.632 1

0.9

0.8

0.7

0.6 Diffusion Coefficient

0.5

0.4

0.3 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Concentration

FIGURE 6.11: Non-linear and constant diffusion functions.

Solving this example problem produced the following non-linear iteration information over the course of the first time step:

Time: 1 second Iteration: 1 L2Norm(F) = 0.1000E+01 Delta=0.1026E+01 Iteration: 2 L2Norm(F) = 0.5549E-01 Delta=0.9876E+00 Iteration: 3 L2Norm(F) = 0.8958E-03 Delta=0.3755E-01 Iteration: 4 L2Norm(F) = 0.2278E-06 Delta=0.5565E-03 Iteration: 5 L2Norm(F) = 0.1481E-13 Delta=0.1438E-06

c Department of Engineering Science, University of Auckland, New Zealand. All rights reserved. July 11, 2002 6.10 SYSTEMS OF NONLINEAR EQUATIONS 89

Note that F is the right hand side vector, so its magnitude (or L2 norm) may be thought of as an indication of how good the solution at that iteration is. The solution is accurate when F is very small. Delta is a measure of how much the solution is changing from one iteration to the next. The Newton iterations are clearly converging.

c Department of Engineering Science, University of Auckland, New Zealand. All rights reserved. July 11, 2002