Anda di halaman 1dari 7

Lagrange Interpolating Polynomials

• The general form for n+1 data points is:


Numerical Methods
n
f n ( x)   Li ( x) f ( xi )
ECE 453

Lecture 11 i 0
n x  xj
Li ( x)  
j 0 xi  x j
j i

designates the “product of”


Interpolation

Lagrange Interpolating Polynomials


Introduction
Estimation of intermediate values between • Linear version (n = 1):
precise data points. The most common method is
Used for 2 points of data: (xo,f(xo)) and (x1,f(x1)),
polynomial interpolation:
f ( x)  a0  a1 x  a2 x 2    an x n x  x1 x  x0
f1 ( x)  f ( x0 )  f ( x1 )
x0  x1 x1  x0
 Polynomial interpolation is used when the point
determined are very precise. The curve
representing the behavior has to pass through Lo (x) L1 ( x)
every point.
 There is one and only one nth-order polynomial
that fits n+1 points

Introduction Lagrange Interpolating Polynomials

• Second order version (n = 2):


x  x1 x  x2  f ( x )
n=3 n=4
n=2
f 2 ( x)  Lo ( x) , j  0
x0  x1 x0  x 2  0

x  x0 x  x2  f ( x ) L1 ( x) , j  1
x1  x0 x1  x 2  1
First order (linear) 2nd order (quadratic) 3rd order (cubic)

x  x0 x  x1  f ( x ) L2 ( x) , j  2
x2  x0 x2  x1  2

Introduction Lagrange Interpolating Polynomials - Example

There are a variety of mathematical formats in Use a Lagrange interpolating polynomial of the
which this polynomial can be expressed: first and second order to evaluate ln(2) on the
basis of the data:
The Newton polynomial (sec. 18.1)
The Lagrange polynomial (sec. 18.2) x0  1 f ( x0)  ln(1)  0
x1  4 f ( x1)  ln(4)  1.386294
x2  6 f ( x 2)  ln(6)  1.791760
Lagrange Interpolating Polynomials – Example Pseudocode – Lagrange interpolation
(cont’d)
• First order polynomial:

x  x1 x  x0
f 1( x)  f ( x 0)  f ( x1)
x 0  x1 x1  x 0
24 2 1
f 1(2)  0  1.386294  0.4620981
1 4 4 1

Lagrange Interpolating Polynomials – Coefficients of an Interpolating Polynomial


Example (cont’d)
• Although “Lagrange” polynomials are well suited for
• Second order polynomial: determining intermediate values between points, they
do not provide a polynomial in conventional form:
x  x1 x  x2 x4 x6
Lo ( x )    
xo  x1 xo  x2 0  4 0  6 f ( x)  a0  a1 x  a2 x 2    a x x n
x  xo x  x 2 x  0 x  6
L1 ( x )     • Since n+1 data points are required to determine n+1
x1  xo x1  x2 4  0 4  6 coefficients, simultaneous linear systems of equations
x  xo x  x1 x  0 x  4 can be used to calculate “a”s.
L2 ( x )    
x2  xo x2  x1 6  0 6  4

Lagrange Interpolating Polynomials – Example Coefficients of an Interpolating Polynomial


(cont’d) (cont’d)
n n
x  xj
f n ( x )   Li ( x ) f ( xi ) Li ( x )   ( j  i) f ( x0 )  a0  a1 x0  a2 x02   an x0n
i 0 j 0 xi  x j
(2  4)( 2  6) f ( x1 )  a0  a1 x1  a2 x12   an x1n
f 2 ( 2)  0
(1  4)(1  6) 
(2  1)( 2  6)
 1.386294 f ( xn )  a0  a1 xn  a2 xn2   an xnn
(4  1)( 4  6)
(2  1)( 2  4) Where “x”s are the knowns and “a”s are the
 1.791760  0.5658444
(6  1)(6  4) unknowns.

Lagrange Interpolating Polynomials – Example


(cont’d) Interpolation
Polynomials are the most common choice
of interpolation because they are easy
to:
Evaluate
Differentiate, and
Integrate.

16
Possible divergence of an extrapolated Possible divergence of an extrapolated
production production

Spline Interpolation
Why Spline Interpolation?
• Polynomials are the most common choice of
interpolants.
• There are cases where polynomials can lead to
erroneous results because of round off error and
overshoot.
• Alternative approach is to apply lower-order
polynomials to subsets of data points. Such
Apply lower-order polynomials to subsets of data points. Spline
connecting polynomials are called spline functions.
provides a superior approximation of the behavior of functions that
have local, abrupt changes.

18

Why Splines ?
1
f ( x) 
1  25 x 2
Table : Six equidistantly spaced points in [-1, 1]
1
x y
1  25 x 2

-1.0 0.038461

-0.6 0.1

-0.2 0.5

0.2 0.5

0.6 0.1
Spline provides a superior approximation of the behavior
1.0 0.038461 Figure : 5th order polynomial vs. exact function
of functions that have local, abrupt changes (d).
19

Spline Interpolation
Why Splines ? The concept of spline is using a thin , flexible strip
(called a spline) to draw smooth curves through a set
of points….natural spline (cubic)
17th Order
Polynomial

Original
Function

5th Order
Polynomial

9th Order
Polynomial

Figure : Higher order polynomial interpolation is a bad idea


20
Quadric Splines
• Objective: to derive a second order polynomial for each
interval between data points. f i ( x)  ai x 2  bi x  ci
• Terms: Interior knots and end points

For n+1 data points:


• i = (0, 1, 2, …n),
• n intervals,
• 3n unknown
constants (a’s, b’s and
c’s)

Linear Spline Quadric Splines

The first order splines for a group of ordered data • The function values of adjacent polynomial
points can be defined as a set of linear functions: must be equal at the interior knots 2(n-1).
ai 1 xi 1  bi 1 xi 1  ci 1  f i ( xi 1 ) i  2, 3, 4,..., n
2

f ( x)  f ( x0 )  m0 ( x  x0 ) x0  x  x1 ai xi 1  bi xi 1  ci  f i ( xi 1 ) i  2, 3, 4,..., n
2

f ( x)  f ( x1 )  m1 ( x  x1 ) x1  x  x2
 • The first and last functions must pass through
f ( x)  f ( xn1 )  mn1 ( x  xn1 ) xn1  x  xn the end points (2).
a1 x0  b1 x0  c1  f ( x0 )
2

f ( xi 1 )  f ( xi ) an xn  bn xn  cn  f ( xn )
2
mi 
xi 1  xi

Linear spline - Example


Quadric Splines
Fit the following data with first order splines. • The first derivatives at the interior knots
Evaluate the function at x = 5. must be equal (n-1).
2.5  1
f i ( x)  2ai x  bi
'
x f(x) m  0.6
7  4.5
f (5)  f (4.5)  m(5  4.5) 2ai 1 xi 1  bi 1  2ai xi 1  bi
3.0 2.5
4.5 1.0  1.0  0.6  0.5 • Assume that the second derivate is zero at
7.0 2.5
 1.3 the first point (1)
9.0 0.5
a1  0
(The first two points will be connected by a straight line)

Linear Spline Quadric Splines - Example


• The main disadvantage of linear spline is that they are Fit the following data with quadratic splines.
not smooth. The data points where 2 splines meets
called (a knot), the changes abruptly. Estimate the value at x = 5.
x 3.0 4.5 7.0 9.0
• The first derivative of the function is discontinuous at f(x) 2.5 1.0 2.5 0.5
these points.

• Using higher order polynomial splines ensure


smoothness at the knots by equating derivatives at Solutions:
these points. There are 3 intervals (n=3), 9 unknowns.
Quadric Splines - Example
Quadric Splines - Example
1. Equal interior points:
 For first interior point (4.5, 1.0) 4.5 1 0 0 0 0 0 0  b1  1 
0 0 20.25 4.5 1 0 0 0  c  1 
The 1st equation:   1   
0 0 49 7 1 0 0 0  a2  2.5
x12 a1  x1b1  c1  f ( x1 )     
0 0 0 0 0 49 7 1  b2   2.5
(4.5) 2 a1  4.5b1  c1  f (4.5) 20.25 a1  4.5 b1  c1  1.0 3 1 0 0 0 0 0 0  c2  2.5
    
The 2nd equation: 0 0 0 0 0 81 9 1  a3  0.5
1 0  9 1  b  0 
x12 a2  x1b2  c2  f ( x1 ) 
0 0 0 0
 3   
0 0 14 1 0  14 1 0  c3  0 
(4.5) 2 a2  4.5b2  c2  f (4.5) 20.25a2  4.5b2  c2  1.0

Quadric Splines - Example Quadric Splines - Example

 For second interior point (7.0, 2.5)


Solving these 8 equations with 8 unknowns

The 3rd equation: a1  0, b1  1, c1  5.5


x a  x2b2  c2  f ( x2 )
2 a2  0.64, b2  6.76, c2  18.46
2 2

(7) 2 a2  7b2  c2  f (7) 49a2  7b2  c2  2.5 a3  1.6, b3  24.6, c3  91.3

The 4th equation: f1 ( x)   x  5.5, 3.0  x  4.5


x22 a3  x2b3  c3  f ( x2 ) f 2 ( x)  0.64 x 2  6.76 x  18.46, 4.5  x  7.0

(7) 2 a3  7b3  c3  f (7) 49a3  7b3  c3  2.5 f3 ( x)  1.6 x 2  24.6 x  91.3, 7.0  x  9.0

Quadric Splines - Example Cubic Splines

 First and last functions pass the end points Objective: to derive a third order polynomial for
each interval between data points.
For the start point (3.0, 2.5)
Terms: Interior knots and end points
x02 a1  x0 b1  c1  f ( x0 ) 9a1  3b1  c1  2.5
f i ( x)  ai x 3  bi x 2  ci x  d i

For the end point (9, 0.5) For n+1 data points:
• i = (0, 1, 2, …n),
x32 a1  x3b3  c3  f ( x3 ) 81a3  9b3  c3  0.5 • n intervals,
• 4n unknown constants (a’s, b’s ,c’s and d’s)

Quadric Splines - Example Cubic Splines


Equal derivatives at the interior knots. • The function values must be equal at the interior knots
(2n-2).
For first interior point (4.5, 1.0)
• The first and last functions must pass through the end
2 x1 a1  b1  2 x1 a2  b2 9a1  b1  9a2  b2 points (2).
• The first derivatives at the interior knots must be equal
For second interior point (7.0, 2.5) (n-1).
2 x2 a2  b2  2 x3 a3  b3 14a2  b2  14a3  b3 • The second derivatives at the interior knots must be
equal (n-1).
• The second derivatives at the end knots are zero (2), (the 2nd
Second derivative at the first point is 0 derivative function becomes a straight line at the end points)
f '' ( x0 )  a1  0
Alternative technique to get Cubic Splines Cubic Splines - Example
• The second derivative within each interval [xi-1, xi ] is a straight line. (the 2nd  For 1st interior point (x1 = 4.5)
derivatives can be represented by first order Lagrange interpolating x 3.0 4.5 7.0 9.0
polynomials.
f(x) 2.5 1.0 2.5 0.5
- xi  xi 1  x1  x0  4.5  3.0  1.5
A straight line
x  xi x  xi 1 - xi 1  xi 1  x2  x0  7  3.0  4
f i ( x)  f i ( xi 1 )  f i ( xi )
'' '' ''
connecting the first
xi 1  xi xi  xi 1 knot f’’(xi-1) and the - xi 1  xi  x2  x1  7  4.5  2.5
second knot f’’(xi)
Apply the following equation:
The second derivative at any point x within the interval ( xi  xi 1 ) f '' ( xi 1 )  2( xi 1  xi 1 ) f '' ( xi )  ( xi 1  xi ) f '' ( xi 1 )


6
 f ( xi 1 )  f ( xi )  6  f ( xi 1 )  f ( xi )
xi 1  xi xi  xi 1

Cubic Splines Cubic Splines - Example


• The last equation can be integrated twice
6 6
2 unknown constants of integration can be evaluated by 1.5 f '' (3)  2  4 f '' (4.5)  2.5 f '' (7)  (2.5  1)  (2.5  1)
applying the boundary conditions: 2.5 1.5
Since f (3)  0
''
1. f(x) = f (xi-1) at xi-1
2. f(x) = f (xi) at xi 8 f '' (4.5)  2.5 f '' (7)  9.6 .............. (eq.1)
'' ''
f i ( x) 
f i ( xi 1 )
xi  x 3  f i ( xi ) x  xi 1 3  For 2nd interior point (x2 = 7 )
6xi  xi 1  6xi  xi 1 
Unknowns:

f ' ' ( xi )
 f ( x ) f '' ( x )  x  x   x 3.0 4.5 7.0 9.0
  i i 1  i i 1 i i 1  xi  x  f(x) 2.5 1.0 2.5 0.5
 xi  xi 1 6  f ' ' ( xi 1 )
i = 0, 1,…, n xi  xi 1  x2  x1  7  4.5  2.5
 f (x ) f ( x ) x  x  
''
  i i  i i i i 1   x  xi 1  xi 1  xi 1  x3  x1  9  4.5  4.5
x  x
 i i 1 6 
xi 1  xi  x3  x2  9  7  2

Cubic Splines Cubic Splines - Example


• For each interior point xi (n-1): f i' 1 ( xi )  f i ( xi )
'
Apply the following equation:

( xi  xi 1 ) f ( xi 1 )  2( xi 1  xi 1 ) f ( xi )
'' ''
( xi  xi 1 ) f '' ( xi 1 )  2( xi 1  xi 1 ) f '' ( xi )  ( xi 1  xi ) f '' ( xi 1 )
 ( xi 1  xi ) f '' ( xi 1 ) 
6
 f ( xi 1 )  f ( xi ) 
6
 f ( xi 1 )  f ( xi )  6  f ( xi 1 )  f ( xi )
xi 1  xi xi 1  xi xi  xi 1

6
 f ( xi 1 )  f ( xi ) 2.5 f '' (4.5)  2  4.5 f '' (7)  2 f '' (9) 
6
(0.5  2.5) 
6
(1  2.5)
xi  xi 1 2 2.5
Since f '' (9)  0
This equation result with n-1 unknown second
derivatives where, for boundary points: 2.5 f '' (4.5)  9 f '' (7)  9.6 ............. (equ 2)
f˝(xo) = f˝(xn) = 0

Cubic Splines - Example Cubic Splines - Example


Solve the two equations:
Fit the following data with cubic splines 8 f i '' (4.5)  2.5 f i '' (7)  9.6 

 yeild f (4.5)  1.67909, f (7)  1.53308
'' ''

Use the results to estimate the value at x=5. 2.5 f i '' (4.5)  9 f i '' (7)  9.6

x 3.0 4.5 7.0 9.0 The first interval (i=1), apply for the equation:
f(x) 2.5 1.0 2.5 0.5 '' ''
f i ( x) 
f i ( xi 1 )
xi  x 3  fi ( xi ) x  xi 1 3
6xi  xi 1  6xi  xi 1 
Solution:
 f ( x ) f '' ( x )  x  x    f (x ) f ( x ) x  x  
''

 Natural Spline:   i i 1  i i 1 i i 1 xi  x    i i  i i i i 1 x  xi 1 


 xi  xi 1 6   xi  xi 1 6 
 2.5 0(1.5) 
f '' ( x0 )  f '' (3)  0, f '' ( x3 )  f '' (9)  0 f1 ( x)  0 ( xi  3)3 
1.67909
( x  3) 3    4.5  x    1  1.67909(1.5) ( x  3)
6(1.5)  1.5 6  1.5 6 

f1 ( x)  0.186566 ( x  3)3  1.6667 (4.5  x)  0.24689( x  3)


Cubic Splines - Example
The 2nd interval (i =2), apply for the equation:
 1.53308  1  1.67909(2.5) 
 7  x 
1.67909
f 2 ( x)  (7  x ) 3  ( x  4.5) 3   
6(2.5) 6(2.5)  2.5 6
 2.5  1.53308(2.5) 
   ( x  4.5)
 2.5 6

f 2 ( x)  0.111939(7  x)3  0.102205 ( x  4.5)3  0.29962(7  x)  1.638783 ( x  4.5)

The 3rd interval (i =3),

f 3 ( x)  0.127757(9  x)3  1.761027 (9  x)  0.25 ( x  7)

For x = 5: f 2 ( x)  f 2 (5)  1.102886

Anda mungkin juga menyukai