Sei sulla pagina 1di 23

CHAPTER 3

NUMERICAL METHODS

Roots of Nonlinear equations

Interpolation (In -Dimension)

Numerical Integration

Numerical Solution of Differential Equations

3.1.1 Newton-Raphson Method

Tangent line of f (x) is f (x). This is the basic of


Newton-Raphson Method described below.
f (x)

f (x0)

f (x1)
f (x2)
O

x 0 x1

x2

Figure 3.2 Newton-Raphson Method


2

Gradient of the tangent line of f (x) at


(x0, f (x0)) is given by f (x0). If we continue
the tangent line at (x0, f (x0)) to (x1,0), then
the gradient of this tangent line can be
determined by 0 f ( x )
0
.
x1 x0

Equalizing these two values, we have


0 f ( x0 )
f ( x0 )
x1 x0
'

or

f ( x0 )
x1 x0 '
.
f ( x0 )

(4)
3

This means that from the initial value x0, using


formula (4), we can compute x1 which is close
to the solution of f (x) 0.
Using the same formula, we can compute x2
which is a better approximation to the solution
compare to x1.

We can also compute x3 , x4 , and so on.

We hope that our iteration converges to the


solution of f (x) 0.
4

In general, Newton-Raphson method can be


formulated as

f ( xi )
xi 1 xi '
.
f ( xi )

Example 3.4
3
Solve f ( x) x 3 x 1 0.
Solution
i ) Differentiate f ( x) to obtain f ' ( x) 3x 2 3.
ii ) Choose x0 0 as a starting point.
iii ) Make a table based on Newton - Raphson' s formula :

xi

f (xi)

f (xi)

-1

-3

-0.333333

-0.037037

-2.666667

-0.347222

-0.000196

-2.638310

-0.347296

-0.000000

What if we choose x0 0.99 ?


Look at the following table.
i

xi

f (xi)

f (xi)

0.99

-2.999701

-0.0597

-49.256248 -119 358.65

We can see from the table


that f ( x1 ) is farer from zero than f ( x0 ) .
This means that Newton - Raphson method fails.
7

IMPORTANT!!!

Newton-Raphson method fails if the


approximate root of equation, for instance
x = x0, close to roots of f (x) = 0.

Therefore, we have to make sure that the


starting point x0 does not give f (x0) close
to zero.

The reason is that dividing a number by a


value close to zero will give a number
with large absolute value.
8

3.1.2 Secant Method

This method is a revision of Newton-Raphson


method as described in the following figure.
f (x)

f (x0)

f (x1)
f (x2)
f (x3)
O

x0 x1 x2 x3

Figure 3.3 Secant Method

x
9

In this method, we begin with two initial values x0


and x1. The straight line from (x0, f (x0)) to (x1,f (x1))
is continued to the x-axis.
Let x2 be the value where this straight line intersects
the x-axis.
By equalizing gradient from (x0, f (x0)) to (x1, f (x1))
and gradient from (x1, f (x1)) to (x2,0), we obtain

10

0 f ( x1 ) f ( x1 ) f ( x0 )

x2 x1
x1 x0
or

x1 x0
.
x2 x1 f ( x1 )
f ( x1 ) f ( x0 )

Using the same formula, we compute x3, x4, ... and so on.

We hope that xi converges to the solution of f (x) 0.

11

In general, Secant method can be formulated as

xi xi 1

xi 1 xi f ( xi )
f ( xi ) f ( xi 1 )

12

Example 3.5
Solve f ( x) x 3 3 x 1 0.

Solution
i ) Choose initial values x0 0 and x1 1.
ii ) Make a table based on the formula of Secant method
i

xi

f (xi)

-1

-3

-0.5

0.375

-0.333333

-0.037037

-0.348315

0.002685

-0.347302

0.000016

-0.347296

-0.000000

-0.347296

-0.000000

13

From the table, notice that:


* Iteration xi converges to x - 0.347296.
* Values in column f (xi) go to zero.

(Remark as in Newton-Raphson method)


If f (xi) is farer from zero than f (xi -1), then the
iteration fails. This means that we made a
mistake in estimating xi using this iteration.

14

3.2 Interpolation (In -dimension)

The meaning of interpolation in 2-dimension is


to define a curve that passes through given data
points. As an example, see the following:
x
x

Figure 3.4 Points interpolation


15

3.2.1 Interpolation Polynomial


Consider the following polynomial :
y C0 C1 x C2 x 2 Cn x n ,
where C0 , C1 , Cn are unknown coeficients.
To find C0 , C1 , Cn , we need (n 1) points
( xk , yk ), k 0, 1, , n, with different values of x
to build a system of (n 1) number of consistent
and independent equations.
This implies that the solution of the system
for C0 , C1 , Cn exists and unique.
16

Example 3.6
Given the data points and what
is the unique polynomial that passes through the
data points?
Solution
Since we are given three different points, then
we can only find unique value for three
coefficients: C0, C1 and C2. Then, our
interpolation polynomial is quadratic:
y = C0 + C1x + C2x2.
17

If we substitute the given data points and


to the polynomial, we get the following three
equations:
2 C0
3 C0 + C1 + C2
3 C0 + 3C1 + 9C2.
This is a system of linear equations. The solution is
4
1
C0 2, C1 , C2 .
3
3
18

Thus, the unique interpolation polynomial that


passes through the given data points is

4
1 2
y 2 x x .
3
3

19

3.2.2 Lagrange Method


Let say we are given the following data points :
( x0 , y0 ), ( x1 , y1 ), , ( xn , yn ).
Interpolation polynomial built by Lagrange Method is
y L0 ( x) y0 L1 ( x) y1 L2 ( x) y2 Ln ( x) yn
where
( x x0 )( x x1 ) ( x xi 1 )( x xi 1 ) ( x xn )
Li ( x)
.
( xi x0 )( xi x1 ) ( xi xi 1 )( xi xi 1 ) ( xi xn )
20

Example 3.7
Given the data points and Apply
Lagrange Method to find interpolation polynomial
passing through these points.

Solution
Let ( x0 , y0 ) (0,2), ( x1 , y1 ) (1,3) dan ( x2 , y2 ) (3,3).
Then, Lagrange interpolation polynomial is given by
y L0 ( x) y0 L1 ( x) y1 L2 ( x) y2

21

where
( x x1 )( x x2 )
( x 1)( x 3)
L0 ( x)

( x0 x1 )( x0 x2 ) (0 1)(0 3)
1
1 2 4
( x 1)( x 3) x x 1.
3
3
3
( x x0 )( x x2 ) ( x 0)( x 3)
L1 ( x)

( x1 x0 )( x1 x2 ) (1 0)(1 3)
1
1 2 3
x( x 3) x x.
2
2
2
22

L2 ( x)

( x x0 )( x x1 )
( x 0)( x 1)

( x2 x0 )( x2 x1 ) (3 0)(3 1)

1
1
1
x( x 1) x 2 x.
6
6
6
Substituting Li ( x) to the Lagrange' s equation, we obtain

the interpolation polynomial


3
1
1 2 4

1
1
x x 1 (2) x 2 x (3) x 2 x (3)
3
2
6
3

2
6
4
1
2 x x2.
3
3

23

Potrebbero piacerti anche