M. Dumbser
1 / 23
Analisi NumericaUniversità degli Studi di TrentoDipartimento d‘Ingegneria Civile ed AmbientaleDr.-Ing. Michael Dumbser
Lecture on Numerical Analysis
Dr.-Ing. Michael Dumbser
08 / 11 / 2007
M. Dumbser
2 / 23
Analisi NumericaUniversità degli Studi di TrentoDipartimento d‘Ingegneria Civile ed AmbientaleDr.-Ing. Michael Dumbser
Numerical Solution of Nonlinear Equations
0)( xf
Task: compute approximately the solution x of the nonlinear algebraic equation
If the problem is not in form (1), then it can always be cast into form (1) by putting all terms on the left hand side.
Examples:
(1)
2
2
2
)sin()exp()(
0)sin()exp(
)sin()exp(
xxxxf
xxx
xxx
)()()()(
)()()(
xexhxgxf
xexhxg
M. Dumbser
3 / 23
Analisi NumericaUniversità degli Studi di TrentoDipartimento d‘Ingegneria Civile ed AmbientaleDr.-Ing. Michael Dumbser
Numerical Solution of Nonlinear Equations
0)( xf
Task: compute approximately the solution x of the nonlinear algebraic equation
(1)
Two problems present even at the analytical level:
• For general functions f(x), there may be no solution at all. Example:
• For general functions f(x), there may be more than one solution. Example:
02)sin()( xxf
01)( 2 xxf 1,1 21 xx
M. Dumbser
4 / 23
Analisi NumericaUniversità degli Studi di TrentoDipartimento d‘Ingegneria Civile ed AmbientaleDr.-Ing. Michael Dumbser
x0 x2 x3 x1
x
f
x4
(I) Before we can start using this method, we must guess two points x0 and x1 where the function f(x) has opposite sign, i.e.
The Regula Falsi Method
0)()( 10 xfxf
(II) Now connect the two points (x0, f(x0)) and (x1, f(x1)) with a straight line and compute the intersection of this line with the x-axis, denoted by xi. The point xi is given by
10
1010
ff
fxxfxi
(III) Compute the sign of f(x2) and compare against the signs of f(x0) and f(x1). Then update the interval boundaries according to the result, i.e. set
0)()(if: 00 ii xfxfxx 0)()(if: 11 ii xfxfxx If |f(xi)| < tolerance then STOP (in Maple: break), otherwise go back to step (II).
M. Dumbser
5 / 23
Analisi NumericaUniversità degli Studi di TrentoDipartimento d‘Ingegneria Civile ed AmbientaleDr.-Ing. Michael Dumbser
x0 x2 x3 x1
x
f
x4
Advantages: - it is guaranteed that the method finds a solution of f(x)=0 because we already know that it
the solution is contained in the initial interval [x0;x1]. - The method is very robust and reliable
The Regula Falsi Method
Disadvantage: - it can not be applied if we do not have an initial guess of the interval [x0;x1].
M. Dumbser
6 / 23
Analisi NumericaUniversità degli Studi di TrentoDipartimento d‘Ingegneria Civile ed AmbientaleDr.-Ing. Michael Dumbser
x0x2 x1
x
f
x3
• Variant of the regula falsi method: we start from any two points x0 and x1
The Secant Method
• Advantage: no initial interval must be guessed
• Disadvantage: may not always converge towards a solution !
M. Dumbser
7 / 23
Analisi NumericaUniversità degli Studi di TrentoDipartimento d‘Ingegneria Civile ed AmbientaleDr.-Ing. Michael Dumbser
x0 x1
x
f
• Variant of the regula falsi method: we start from any two points x0 and x1
The Secant Method
• Advantage: no initial interval must be guessed
• Disadvantage: may not always converge towards a solution !
M. Dumbser
8 / 23
Analisi NumericaUniversità degli Studi di TrentoDipartimento d‘Ingegneria Civile ed AmbientaleDr.-Ing. Michael Dumbser
x0x1
x
f
• Differential form of the secant method. Instead of using the secant, Newton proposes to use the tangent!
Newton‘s Method
• Advantages: - no initial interval must be guessed - very fast
• Disadvantage: may not always converge towards a solution !
x2
M. Dumbser
9 / 23
Analisi NumericaUniversità degli Studi di TrentoDipartimento d‘Ingegneria Civile ed AmbientaleDr.-Ing. Michael Dumbser
x0x1
x
f
Newton‘s Method
x2
• Differential form of the secant method. Instead of using the secant, Newton proposes to use the tangent!
0)(
ii xxx
fxf
x
fxfx i
/)(
xxx ii 1
ixxx :
(1) If |f(xi)| < tolerance then STOP (in Maple/MATLAB: break) or(2) If | x | < tolerance then STOP
M. Dumbser
10 / 23
Analisi NumericaUniversità degli Studi di TrentoDipartimento d‘Ingegneria Civile ed AmbientaleDr.-Ing. Michael Dumbser
Exercise 1
Write a Maple worksheet and a MATLAB script that solve the nonlinear equation
using the regula falsi method. Choose an appropriate starting interval.
Exercise 2
Now write a MATLAB script that solves the problem of exercise 1 using the Newton method. The user should have the possibility to choose the starting guess, the maximum number of iterations as well as the tolerance.
0)sin()exp()( 2 xxxxf
M. Dumbser
11 / 23
Analisi NumericaUniversità degli Studi di TrentoDipartimento d‘Ingegneria Civile ed AmbientaleDr.-Ing. Michael Dumbser
Globally Convergent Newton Methods
From the previous Example 4 we find that even for strictly monotone functions f(x) Newton‘s method may not always converge from arbitrary starting points x0, but only from starting points that are sufficiently close to the solution of the problem. However, if the starting point is sufficiently close, the method converges. We therefore say the original Newton method is only locally convergent.
The local convergence behaviour of Newton‘s method and the possible failure to converge for initial guesses far away from the solution can be mainly explained by too large step sizes x:
M. Dumbser
12 / 23
Analisi NumericaUniversità degli Studi di TrentoDipartimento d‘Ingegneria Civile ed AmbientaleDr.-Ing. Michael Dumbser
Globally Convergent Newton Methods
As seen in the sketch of the previous slide, the absolute value of the function f(x) slightly increased during one Newton step. To avoid this problem, we therefore add the following requirement: The function |f(x)| must always decrease during one Newton step, i.e.:
)()( iii xfxxf
x
fxfx i
/)(
xxx ii 1
If this is not fulfilled, the step size is sucessively reduced until the criterion is satisfied. The globally convergent Newton method then reads as follows:
)()( iii xfxxf 1
10
WHILE
END
DO i=0,1,…
UNTIL tolxf i )(
Free parameter. Choose e.g. = 0.5
M. Dumbser
13 / 23
Analisi NumericaUniversità degli Studi di TrentoDipartimento d‘Ingegneria Civile ed AmbientaleDr.-Ing. Michael Dumbser
Globally Convergent Newton Methods
Exercise 5
Write a modified MATLAB script GlobalNewton.m to solve the nonlinear equation
with the globally convergent Newton method.
0)1arctan()( xxf
1) Use x0 = 2 as initial guess.
2) Use x0 = 2.5 as initial guess. What do you realize?
3) Use x0 = 106 as initial guess. Does the method converge?
M. Dumbser
14 / 23
Analisi NumericaUniversità degli Studi di TrentoDipartimento d‘Ingegneria Civile ed AmbientaleDr.-Ing. Michael Dumbser
Computation of the Roots of a Polynomial
We now apply Newton‘s method to a special case of nonlinear algebraic equation where thefunction f(x) is a polynomial of degree n:
The values x which satisfy eqn. (1) are called the roots of the polynomial pn(x).We suppose in the following that all the roots of the polynomial are distinct and real.
0)()(0
n
i
iin xaxpxf
Suppose x = is a root of pn(x), i.e.
then we have
If we knew all the roots i we would have the following expression of the polynomial:
)()()( 1 xpxxp nn
0)( np
))...()(()( 21 nn xxxxp
M. Dumbser
15 / 23
Analisi NumericaUniversità degli Studi di TrentoDipartimento d‘Ingegneria Civile ed AmbientaleDr.-Ing. Michael Dumbser
Computation of the Roots of a Polynomial
A simple and straightforward application of Newton‘s method now consists in finding a firstroot 1 (typically the largest one) of the polynomial pn and then compute the largest root 2 of the polynomial pn-1 obtained by dividing the polynomial pn by ( x – ):
11
)()(
x
xpxp n
n
After having found the root 2 of pn-1 we divide again
))((
)()()(
212
12
xx
xp
x
xpxp nn
n
and compute the next root 3 and so on, until all the n roots of pn have been found. In general, we have:
))...((
)()(
1 j
njn xx
xpxp
j
i ij
n
j
nxjn xxx
xp
xx
xpxp
x 111
1
))...((
)(
))...((
)()(
M. Dumbser
16 / 23
Analisi NumericaUniversità degli Studi di TrentoDipartimento d‘Ingegneria Civile ed AmbientaleDr.-Ing. Michael Dumbser
Computation of the Roots of a Polynomial
To express the polynomial pn-j(x) and its derivative, two simple MATLAB loops defining the auxiliary variables Dj and Sj are necessary:
j
njn D
xpxp
)()(
jj
n
j
nxjn S
D
xp
D
xpxp
x
)()(
)(
END
)(*
j]:[1k FOR
1
kjj
j
xDD
D
with
END
)/(1
j]:[1k FOR
0
kjj
j
xSS
S
jnnx
njnijn Spp
pp
xxp
x
fxfx
/)(/)(
We then obtain the so-called Newton-Maehly method:
M. Dumbser
17 / 23
Analisi NumericaUniversità degli Studi di TrentoDipartimento d‘Ingegneria Civile ed AmbientaleDr.-Ing. Michael Dumbser
Exercise 3
(1) Write a MATLAB script PolyRoot.m that finds all the roots of a general polynomial of degree n. The user should be able to specify the coefficients a of the polynomial. Then, two MATLAB function files, called Polynomial.m and DPolynomial.m compute the polynomial and its first derivative in point x using the coefficients a. Further user inputs required are tol, NMAX and x0.
(2) Apply your general MATLAB script to the particular polynomial
(3) Now try your MATLAB program on the polynomial
Hint: Use Maple to rewrite this polynomial in standard form
2
1
4
3x
4
73)( 234 xxxxp
12
0
)2()(j
jxxp
n
j
jjxaxp
0
)(
M. Dumbser
18 / 23
Analisi NumericaUniversità degli Studi di TrentoDipartimento d‘Ingegneria Civile ed AmbientaleDr.-Ing. Michael Dumbser
Efficient Evaluation of Polynomials
The standard format of defining a polynomial is computationally not the most efficient way toevaluate a polynomial:
...)( 43210 xxxxaxxxaxxaxaaxp
A computationally more efficient but mathematically fully equivalent way of writing the polynomialp(x) is the so called Horner scheme, which uses the distributive law:
...)( 44
33
2210 xaxaxaxaaxp
In this example, we have 4 additions and 10 multiplications
...)( 43210 axaxaxaxaxp
Now, we still have 4 additions but only 4 multiplications!
M. Dumbser
19 / 23
Analisi NumericaUniversità degli Studi di TrentoDipartimento d‘Ingegneria Civile ed AmbientaleDr.-Ing. Michael Dumbser
Globally Convergent Newton Methods
Exercise 4
Now try your original MATLAB script Newton.m to solve the nonlinear equation
0)1arctan()( xxf
1) Use x0 = 2 as initial guess.
2) Use x0 = 2.5 as initial guess. What do you realize?
M. Dumbser
20 / 23
Analisi NumericaUniversità degli Studi di TrentoDipartimento d‘Ingegneria Civile ed AmbientaleDr.-Ing. Michael Dumbser
Newton‘s Method for Systems of Equations
0)(
ii xxx
fxf
)(1ixfDx
xxx ii
1
ixxx
:
(1) If ||f(xi)|| < tolerance then STOP (in Maple/MATLAB: break) or(2) If || x || < tolerance then STOP
The extension of Newton‘s method to systems of nonlinear algebraic equations with several unknown variables is straightforward.
0)( xf
The problem is written in standard form in matrix-vector notation as follows:
Linearization (multi-dimensional Taylor series up to first order) leads to:
j
iij x
f
x
fDD
:
The matrix D is called the Jacobian matrix of the vector function f with respect to ist vector argument x and is the multi-dimensional equivalent to the first derivative of a scalar function.
This corresponds to solving the linear system )( ixfxD
i.e. the vector norm of f is the so-called function residual.
222
21 ...)( nfffxf
M. Dumbser
21 / 23
Analisi NumericaUniversità degli Studi di TrentoDipartimento d‘Ingegneria Civile ed AmbientaleDr.-Ing. Michael Dumbser
Exercise 6
Write a MATLAB script NewtonSys.m that solves the nonlinear system of equations
using the Newton method for systems. The user should have the possibility to choose the initial guess for the vector of unknowns, the maximum number of iterations as well as the tolerance. The vector function and its Jacobian matrix should be implemented in two separate .m files, called FuncSys.m and DFuncSys.m.
021)2sin()1exp()2,1( 221 xxxxxxf
021)2sin()1cos()2,1(2 xxxxxxf
M. Dumbser
22 / 23
Analisi NumericaUniversità degli Studi di TrentoDipartimento d‘Ingegneria Civile ed AmbientaleDr.-Ing. Michael Dumbser
Globally Convergent Newton‘s Method for Systems
The extension of the globally convergent Newton‘s method to systems of nonlinear algebraic equations with several unknown variables is done as in the scalar case:
)(
1
ixfx
fx
xxx kii
1
)()( iiki xfxxf
10
10
WHILE
kk 1
END
DO i=0,1,…
UNTIL tolxf i )(
0k
1kk
M. Dumbser
23 / 23
Analisi NumericaUniversità degli Studi di TrentoDipartimento d‘Ingegneria Civile ed AmbientaleDr.-Ing. Michael Dumbser
Exercise 7
We want to solve the following nonlinear system of equations:
(1) Use the classical Newton method for systems starting from [0,0]
(2) Use the classical Newton method for systems starting from [1000,1000]
(3) Can you find a starting point from which the classical Newton method converges?
(4) Construct a globally convergent Newton method for systems and start again from the points [0,0] and [1000,1000]. Does the global method even converge from the starting point [1e6,1e6] ?
0)arctan()1arctan(),( yxyxf
03
1)exp(),( 2 yxyxg