Numerical Methods
Numerical Methods
and
x x1 x x0
L0 ( x) L1 ( x)
x0 x1 x1 x0
Lagrange Interpolating Polynomials
• The linear Lagrange Interpolating Polynomial through (x0, y0) and (x1,
y1) is
P( x) L0 ( x) f ( x0 ) L1 ( x) f ( x1 )
x x1 x x0
P( x) f ( x0 ) f ( x1 )
• Note that x0 x1 x1 x0
L0implies
• This 1, L0 ( x1 ) 0, L1 ( x0 ) 0, L1 ( x1 ) 1
( x0 ) that
P( x0 ) 1 f ( x0 ) 0 f ( x1 ) f ( x0 ) y0
P is thePunique polynomial
( x1 ) 0 f ( x0of) degree
1 fat( x
most one that passes through
1 ) f ( x1 ) y1
(x0,y0) and (X1, y1)
Lagrange Interpolating Polynomials
x x1 x 5 1
L0 ( x ) ( x 5)
x0 x1 25 3
x x1 x2 1
L1 ( x ) ( x 2)
x0 x1 52 3
1 1
P( x) ( x 5) 4 ( x 2) 1
3 3
P( x) x 6
Lagrange Interpolating Polynomials
• Example:
The graph of y = P(x) is shown in the figure
3
y = P(x) = - x + 6
2
0
1 2 3 4 5
Lagrange Interpolating Polynomials
• If x0, x1,…xn are n+1 distinct numbers and f is a function whose values
are given at these numbers, then a unique polynomial P(x) of degree
at most n exist with
for k = 0,1,…n
f ( xk )isgiven
• The polynomial P(by
xk )
P ( x ) Ln , 0 ( x ) f ( x0 ) ... Ln , n ( x) f ( xn )
n
P( x)
k 0
f ( xk ) Ln , k ( x )
Lagrange Interpolating Polynomials
• Where
( x x0 )( x x1 )...(x xk 1 )( x xk 1 )...(x xn )
Ln ,k ( x)
( xk x0 )( xk x1 )...(xk xk 1 )( xk xk 1 )...(xk xn )
n
x xi
Ln ,k ( x)
i 0 xk xi
ik
or Ln,k (x) can simply be written as when there is no confusion
as to its degree
Lk (x)
Lagrange Interpolating Polynomials
• Example:
a.) Use the number x0 = 2, x1 = 2.75 and x2 = 4 to find the second
Lagrange Interpolating polynomial for f(x) = 1/x
b.) use this polynomial to approximate f(3) = 1/3
( x 2.75)( x 4) 2
L0 ( x ) ( x 2.75)( x 4)
( 2 2.75)(2 4) 3
( x 2)( x 4) 16
L1 ( x ) ( x 2)( x 4)
( 2.75 2)(2.75 4) 15
( x 2)( x 2.75) 2
L2 ( x ) ( x 2)( x 2.75)
( 4 2)(4 2.5) 5
Lagrange Interpolating Polynomials
Also, therefore,
1
f ( x0 ) f (2) 2
2 P ( x ) f ( xk ) Lk ( x )
1 4 k 0
f ( x1 ) f ( 2.75)
2.75 11 1 2 35 49
1 P( x) x x
f ( x2 ) f (4) 22 88 44
4
An approximation to f(3) = 1/3
9 105 49 29
f (3) P (3) 0.32955
22 88 44 88
Lagrange Interpolating Polynomials
EXERCISES:
1. For the given function f(x), let x0 = 0, x1 = 0.6 and x2 = 0.9. Construct
interpolation polynomials of degree at most one and at most two to
approximate f(0.45)
1. f ( x ) cos x
2. f ( x ) 1 x
3. f ( x ) ln( x 1)
4. f ( x ) tan x
Lagrange Interpolating Polynomials
EXERCISES:
2. For the given function f(x), let x0 = 1, x1 = 1.25 and x2 = 1.6.
Construct interpolation polynomials of degree at most one and at
most two to approximate f(1.4)
1. f ( x ) sin x
2. f ( x ) 3 x 1
3. f ( x ) log10 (3 x 1)
4. f ( x ) e 2x
x
Data Approximation and Neville’s Method
( x xi ) * Pi 1, j ( xi 1 x) * Pi , j 1
Pi , j
xi j xi
Data Approximation and Neville’s Method
Example:
Table below lists values of a function f at various points. The
approximation requires to interpolate for x = 27.5
x f(x)
10.1 0.17537
22.2 0.37784
32.0 0.52992
41.6 0.66393
50.5 0.63608
Data Approximation and Neville’s Method
Example:
x Pi0 Pi1 P12 P13 Pi4
EXERCISES:
1. Use Neville’s method to obtain the approximation for Lagrange
interpolating polynomials of degrees one, two and three to
approximate each of the following:
1
1. f (8.4) 2. f ( )
3
f (8.1) 16.94410
f ( 0.75) 0.07181250
f (8.3) 17.56492
f ( 0.5) 0.02475000
f (8.6) 18.50515
f ( 0.25) 0.33493750
f (8.7) 18.82091
f (0) 1.10100000
Data Approximation and Neville’s Method
EXERCISES:
2. Use Neville’s method to obtain the approximation for Lagrange
interpolating polynomials of degrees one, two and three to
approximate each of the following:
3. f ( 4.3) 4. f (0.25)
f (0) 1 f ( 1) 0.86199480
f (0.25) 1.64872 f ( 0.5) 0.95802009
f (0.5) 2.71828 f (0) 1.0986123
f (0.75) 4.48169 f (0.5) 1.2943767
Divided Differences
f1 f 0
f x0 , x1 f0
[1]
f 2 f1
f x ,
called the first divided x
1 difference f
[1]
between x11 and x2
x2 x1
2
Divided Differences
• In general,
ft f s
f xs , xt
xt xs
Is the first divided difference between xs and xt
While, the second-and higher-order differences are defined in
terms of lower-order differences
f x1 , x2 f x0 , x1
Say,
f x0 , x1 , x2 f0
[ 2]
x2 x0
xn x0
Divided Differences
Divided Differences
• Example,
xi fi f[xi,xi+1] f[xi,...xi+2] f[xi,...xi+3] f[xi,...xi+4]
3.2 22.0
8.4000
2.7 17.8 2.856
2.118 -0.528
1.0 14.2 2.012 0.256
6.343 0.0865
4.8 38.3 2.263
16.750
The interpolating
5.6 polynomial
51.7 of degree 3 at points x0 = 3.2 to x3 = 4.8, is
• EXERCISESX f(xi)
i
1. 0.765197
1.0
1.3 0.6200860
1.6 0.4554022
1.9 0.2818186
2.2 0.1103623
Complete the divided difference table for the data given, and construct the
interpolating polynomial that uses all the data and interpolate x =1.5
Divided Differences
• EXERCISES
2. f(8.4) if f(8.1)=16.94410, f(8.3) = 17.56492,
f(8.6) = 18.50515, f(8.7) = 18.82091