Numericla Method
Numericla Method
Numericla Method
FOR MECHANICAL
ENGINEERS
INTERPOLATION
Dr. Kais Hbaieb
ME 301
Introduction
n=3 n=4
n=2
x x1 x x0
f1(x) f (x 0 ) f (x1 )
x0 x1 x1 x0
Lo (x) L1(x)
Lagrange Interpolating
Polynomials
f 2 (x)
x x1 x x2 f (x ) Lo (x) , j ≠ 0
x0 x1 x0 x 2 0
x x 0 x x 2
f (x1) L1 (x) , j ≠1
x1 x0 x1 x 2
x x0 xx1 f (x )
L2 (x) , j ≠ 2
x2 x0 x2 x1 2
Lagrange Interpolating Polynomials - Example
x0 1 f ( x 0 ) ln(1) 0
x1 4 f ( x1) ln(4) 1.386294
x2 6 f (x 2) ln(6) 1.791760
Lagrange Interpolating Polynomials – Example
(cont’d)
• First orderpolynomial:
x x1 x x0
f 1(x) f (x 0 ) f (x1)
x0 x1 x1 x0
24 2 1
f 1(2) 0 1.386294 0.4620981
1 4 4 1
Lagrange Interpolating Polynomials –
Example (cont’d)
• Second order polynomial:
x x1 x x2 x 4 x 6
Lo( x)
xo x1 xo x2 0 4 0 6
x xo x x2 x 0 x 6
L1( x)
x1 xo x1 x2 4 0 4 6
x xo x x1 x 0 x 4
L2( x)
x2 xo x2 x1 6 0 6 4
Lagrange Interpolating Polynomials – Example
(cont’d)
n n x xj
f n (x) Li (x) f (xi ) Li ( x) P ( j ≠ i)
i0 j0 xi x j
(2 4)(2 6)
f 2 (2) 0
(1 4)(16)
(2 1)(2 6)
1.386294
(4 1)(4 6)
(2 1)(2 4)
1.791760 0.5658444
(6 1)(6 4)
Lagrange Interpolating Polynomials
– Example (cont’d)
Pseudocode – Lagrange
interpolation
Coefficients of an Interpolating
Polynomial
• Although “Lagrange” polynomials are well suited for
determining intermediate values between points, they
do not provide a polynomial in conventionalform:
f (x) a0 a1 x a2 x 2 … a x x n
• Since n+1 data points are required to determine n+1
coefficients, simultaneous linear systems of equations
can be used to calculate “ a ”s.
Coefficients of an Interpolating
Polynomial (cont’d)
Solutions:
There are 3 intervals (n=3), 9 unknowns.
Quadratic Splines - Example
1. Equal interior points:
For first interior point (4.5, 1.0)
The 1st equation:
x 2 a x b c f (x )
1 1 11 1 1
A straight line
x xi x xi1
f i (x) f i (xi1 ) f i (xi )
'' '' '' connecting the first
xi 1 xi xi xi1 knot f’’(xi-1) and the
second knot f’’(xi)
f ''(xi )
f ''(x i1 )
i = 0, 1,…, n
Cubic Splines
• For each interior point xi (n-1): f'(x
i1 i
) f
i
'
(x )
i
(x x ) f '' (x ) 6
f (xi1 ) f (xi )
i1 i i1
xi 1 xi
6
f (xi1 ) f (xi )
xi x i1
Solution:
Natural Spline:
f '' (x ) f '' (3) 0, f '' (x ) f '' (9) 0
0 3
Cubic Splines - Example
For 1st interior point (x1 =4.5)
x 3.0 4.5 7.0 9.0
f(x) 2.5 1.0 2.5 0.5
- xi xi1 x1 x0 4.5 3.0 1.5
- xi1 xi 1 x2 x0 7 3.0 4
- xi1 xi x2 x1 7 4.5 2.5
Apply the following equation:
(x x ) f '' (x ) 2(x x ) f '' (x ) (x x ) f ''
(xi1 )
i i1 i1 i1 i1 i i1 i
6
f (x i1 ) f (x i ) 6
f (x i1 ) f (x i )
xi1 xi xi xi1
Cubic Splines - Example
6 6
1.5 f '' (3) 2 4 f '' (4.5) 2.5 f '' (7) (2.5 1) (2.5 1)
2.5 1.5
Since f '' (3) 0
8 f '' (4.5) 2.5 f '' (7) 9.6 .............. (eq.1)
xi 1 xi x3 x2 9 7 2
Cubic Splines - Example
Apply the following equation:
(x x ) f '' (x ) 2(x x ) f '' (x ) (x x ) f '' (x )
i i1 i1 i1 i1 i i1 i i1
6
f (xi1 ) f (xi ) 6
f (x i1 ) f (x i )
xi1 xi xi xi1
6 6
2.5 f '' (4.5) 2 4.5 f '' (7) 2 f '' (9) (0.5 2.5) (1 2.5)
2 2.5
Since f '' (9) 0