Download as pdf or txt
Download as pdf or txt
You are on page 1of 31

Spline interpolation

616201 Chemical Engineering Analysis by Numerical Method


Dr. Wasu Chaitree
Heaviside

Spline interpolation Cubic


spline
Step function

Newton and Lagrange methods are good interpolations if high-order


polynomials are applied
• There are cases where polynomials can 5th
lead to erroneous results because of round order
off error and overshoot.
• Alternative approach is to apply lower-
7th
order polynomials to subsets of data order
points. Such connecting polynomials are
called spline functions.
Idea behind splines
• Use lower order polynomials to connect subsets of data Linear spline
points
• Make connections between adjacent splines smooth
•Lower order polynomials avoid oscillations and overshoots 2
Linear Splines
• The simplest connection between two points is a straight line. The first-order splines for a group of ordered
data points can be defi ned as a set of linear functions,

𝑎𝑎1 𝑥𝑥 + 𝑏𝑏1

𝑎𝑎3 𝑥𝑥 + 𝑏𝑏3

𝑎𝑎2 𝑥𝑥 + 𝑏𝑏2

𝑓𝑓𝑖𝑖 𝑥𝑥 = 𝑚𝑚𝑖𝑖 𝑥𝑥 + 𝑏𝑏𝑖𝑖 𝑓𝑓 𝑥𝑥𝑖𝑖+1 − 𝑓𝑓 𝑥𝑥𝑖𝑖


𝑏𝑏𝑖𝑖 = 𝑓𝑓 𝑥𝑥𝑖𝑖 − 𝑥𝑥𝑖𝑖
𝑥𝑥𝑖𝑖+1 − 𝑥𝑥𝑖𝑖

3
2.5 − 1
m= = 0.6
7 − 4.5

𝑓𝑓 5 − 𝑓𝑓(4.5)
0.6 =
5 − 4.5

f 5 = 1.3

xi+1 xi F(x)i+1 F(x) m f(5)


9 3 0.5 2.5 -0.33333 0.5
7 3 2.5 2.5 0 2.5
4
Quadratic Splines
• These “quadratic splines” have continuous first derivatives at the knots. Although quadratic splines do not
ensure equal second derivatives at the knots, they serve nicely to demonstrate the general procedure for
developing high
• The objective in quadratic splines is to derive a second-order polynomial for each interval between data
points. The polynomial for each interval can be represented generally as

3n unknown constants (the a’s, b’s, and c’s) to evaluate.


Therefore, 3n equations or conditions are required to evaluate the
unknowns.

there are n intervals and n +1 data points. The example shown is for n=3.

5
i=2
𝑎𝑎1 𝑥𝑥12 + 𝑏𝑏1 𝑥𝑥1 + 𝑐𝑐1 = 𝑓𝑓(𝑥𝑥1 )
𝑎𝑎2 𝑥𝑥12 + 𝑏𝑏2 𝑥𝑥1 + 𝑐𝑐2 = 𝑓𝑓(𝑥𝑥1 )

Quadratic splines - continuous first derivatives


May have discontinuous second and higher derivatives f i ( x ) = a i x 2 + bi x + c i
Derive second order polynomial between each pair of points
For n+1 points or n intervals & 3n unknown parameters (a’s, b’s, and c’s)
6
Need 3n equations
7
We need one more condition a1 = 0

8
IDeqUntion -> C 1 S) = SCLUATION

PICXIS = x 1 = =1.5 = 991 + 3b15( /


PICXL) = ↑ 1 = 1 =
P2 CX1)
PL( X3)
PS ( X3)
PS ( X4)

9
13
Cubic Splines
• Cubic Splines attempt to solve the problem of the
smoothness of a graph as well as reduce error.
• Polynomial interpolation uses a single polynomial to meet
all data points, while splines use several low degree
polynomials.
• Cubic splines consist of polynomials of degree 3. Cubic
splines add curvature to an interpolation that would
otherwise be only line segments.
• Base points for cubic splines are called knots. Every sections
of a spline begins and ends with a knot.
14
( )= + ( )+ ( ) + ( )

• Piecewise cubic polynomial with continuous derivatives up to order 2


1. The function must pass through all the data points
x xi : si ( xi ) fi ai bi ( xi xi ) ci ( xi xi )2 d i ( xi xi )3 ai
x xi 1 : si ( xi 1 ) fi 1 ai bi ( xi 1 xi ) ci ( xi 1 xi )2 d i ( xi 1 xi )3

gives 2(n-1) equations


ai fi i = 1,2,…, n-1

fi bi hi ci hi2 di hi3 fi 1
16
x xi : si ( xi ) fi ai bi ( xi xi ) ci ( xi xi )2 d i ( xi xi )3 ai
x xi 1 : si ( xi 1 ) fi 1 ai bi ( xi 1 xi ) ci ( xi 1 xi )2 d i ( xi 1 xi )3
2. First derivatives at the interior nodes must be equal:
( )= +2 ( )+3 ( )
( )= ( )
+2 +3 = (n-1) equations

3. Second derivatives at the interior nodes must be equal:


( )=2 +6 ( ) (n-1) equations
( )= ( )
+3 =

17
Two additional conditions are needed (arbitrary)

s1 ( x 1 ) 0 2c1
sn 1 ( x n ) 0 2cn 1 6 d n 1 hn 1

4. The second derivatives at the end knots are zero

s1 ( x 1 ) 0 c1 0
sn 1 ( x n ) 0 cn cn 1 3d n 1 hn 1 0

Total equations: 2(n-1) + (n-1) + (n-1) +2+2 = 4(n-1) 18


Cubic Splines
si ( x ) ai bi ( x xi ) ci ( x xi ) 2 di ( x xi ) 3
• Solve for (ai, bi, ci, di)
fi 1 fi fi fi 1
hi 1 c i 1 2( hi 1 hi )c i hi c i 1 3 3
hi hi 1

3( f [ x i 1 , x i ] f [ x i , x i 1 ])

• Tridiagonal system with boundary conditions c1 = cn= 0


ci 1 ci fi 1 fi hi
ai fi , d i , bi 2ci ci 1
3 hi hi 3
20
Cubic Splines
1 c1
h1 2( h1 h2 ) h2 c2
h2 2( h2 h3 ) h3 c3

hn 2 2( hn 2 hn 1 ) hn 1 cn 1
1 cn
0
3 f [ x 3 , x 2 ] f [ x 2 , x1 ] ทบทวน ่ากระจา ย ง
3 f [ x4 , x3 ] f [ x3 , x2 ]
Tridiagonal matrix
3 f [ xn , xn 1 ] f [ xn 1 , xn 2 ]
0

21
ว่
ยั
CUDI) spline

<40. YOS, <X1941), ( X2942), . . . . <XNeYR)


↑ g"; < xi+1) = g"; +1 ( x 1 +1)
~

D- I Constrain +

4
Constraints

#
PD Unknown S, PM- 2
4)
econstraints extr

>X
is is is &
913x = dicx- xistbixx- xi)" + <i < X- Xi) + di
~

constraint ↑4 UnknownS

9 i ( Xi) = Yi, giCXi+1) = ↑it) ( DCOnstraint

gi ( xite ) = gity ( Xi+1


M-1 COMStraintS
gio( +1) = า ( x2) (
า (2) = g'23XL
/
ค่
ง่
Define Hi = x +1 - Xi, Hi = yit- y ↑

&1 = 4

ginis tbihi +Citi+&1 = Hi

sainit (bini + ( i = ( +
saini + ebi = 2bit1

-solved for di in terms bi

-solved for ci interms bi

With_ Hi
Thibi + ICHit DitISbit) +
Initbit = Hits Hi
Start 1= 3

Fit cubic splines to the same data used in Table 18.1


And estimate the value at x = 5.

·
·
·

เ น 84
=

262 (1 + DLC2
มอง A -

(1 = · SALC 1 =

·
( ) 2.5 1
, = = = 0.6
7 4.5
3( , , )=4.8

1 2.5
, = = 1
4.5 3
22
ป็
ci 1 ci fi 1 fi hi
ai fi , d i , bi 2ci ci 1
3 hi hi 3

23
S2(x=5) =1.1028

24
Cubic equation for each interval
Two unknows are second derivatives at the end of each interval, so we can determine them from
the following equation

Remember, the second derivatives at the end knots are zero = =0

25
i=1, x1=4.5

3 = 9 =0
i=2, x2=7

26
27
0 ใบ
Quiz
constreng ทเร ีย

1)

2)

29
SIX) cubic spline -> FICX), flCX) cubic spline
=121 = =2 ( 1

รา (1) ==2 (1

า(1) ==2 (1

Fico) = 8, file) =
="IXO) = 0 , ↑"3 Ans =

SIX) At X= /
fl( KS = 1 + &- OX" + by
( 2- 1+1 = (
1tb = 1- 1
fil ( X) = 1 - 2 &X + 3bx 2
1:
='(x) at X= 1
fi ( X = - ( &+66X
Ot
1- 3 :
+&( X- 1) + 2 CX-
2) + ( X- 2) 153b = Its ,
Fil X) =
=- - - - 5
- 2)
="(X) At X= /
f's ( X) = +21( /- 2) + 33
66 = - 6 > b=- 1
ว (X) ==27 +61x-1

:. b = - 1. 6 = 2.=- 5
fico 3 = 0 -> a =

(2) =->>- 2
ร่
ร่
ร้

You might also like