Home > Numerical methods calculators > Cubic spline interpolation example

Cubic spline interpolation example ( Enter your problem )
  1. Formula
  2. Example-1 (Fit 4 points)
  3. Example-2 (Fit 4 points)
  4. Example-3 (Fit 3 points)
  5. Example-4 (Fit 3 points)
  6. Example-5 (Fit 5 points)
  7. Example-6 (Fit 5 points)

1. Formula
(Previous example)
3. Example-2 (Fit 4 points)
(Next example)

2. Example-1 (Fit 4 points)





Formula
Cubic spline formula is `f(x)=(x_i-x)^3/(6h) M_(i-1) + (x-x_(i-1))^3/(6h) M_i + ((x_i-x))/h (y_(i-1)-h^2/6 M_(i-1)) + ((x-x_(i-1)))/h (y_i-h^2/6 M_i) ->(1)`
`M_(i-1)+4M_(i)+M_(i+1)=6/h^2(y_(i-1)-2y_(i)+y_(i+1))->(2)`

Examples
1. Calculate Cubic Splines
X1234
Y15118
y(1.5), y'(2)


Solution:
x1234
y15118

Cubic spline formula is
`f(x)=(x_i-x)^3/(6h) M_(i-1) + (x-x_(i-1))^3/(6h) M_i + ((x_i-x))/h (y_(i-1)-h^2/6 M_(i-1)) + ((x-x_(i-1)))/h (y_i-h^2/6 M_i) ->(1)`

We have, `M_(i-1)+4M_(i)+M_(i+1)=6/h^2(y_(i-1)-2y_(i)+y_(i+1))->(2)`

Here `h=1,n=3`

`M_0=0,M_3=0`

Substitute `i=1` in equation `(2)`

`M_0+4M_1+M_2=6/h^2(y_0-2y_1+y_2)`

`=>0+4M_1+M_2=6/1*(1-2*5+11)`

`=>4M_1+M_2=12`

Substitute `i=2` in equation `(2)`

`M_1+4M_2+M_3=6/h^2(y_1-2y_2+y_3)`

`=>M_1+4M_2+0=6/1*(5-2*11+8)`

`=>M_1+4M_2=-54`

Solving these 2 equations using elimination method

Total Equations are `2`

`4M_1+M_2=12 -> (1)`

`M_1+4M_2=-54 -> (2)`



Select the equations `(1)` and `(2)`, and eliminate the variable `M_1`.

`4M_1+M_2=12`` xx 1->````4M_1``+``M_2``=``12```
`M_1+4M_2=-54`` xx 4->````4M_1``+``16M_2``=``-216```

`-``15M_2``=``228`` -> (3)`




Now use back substitution method
From (3)
`-15M_2=228`

`=>M_2=(228)/(-15)=-15.2`

From (2)
`M_1+4M_2=-54`

`=>M_1+4(-15.2)=-54`

`=>M_1-60.8=-54`

`=>M_1=-54+60.8=6.8`

Solution using Elimination method.
`M_1=6.8,M_2=-15.2`




Substitute `i=1` in equation `(1)`, we get cubic spline in `1^(st)` interval `[x_0,x_1]=[1,2]`

`f_1(x)=(x_1-x)^3/(6h) M_0 + (x-x_0)^3/(6h) M_1 + ((x_1-x))/h (y_0-h^2/6 M_0)+((x-x_0))/h (y_1-h^2/6 M_1)`

`f_1(x)=(2-x)^3/6 *0 + (x-1)^3/6 *6.8 + ((2-x))/1 (1-1/6 *0) + ((x-1))/1 (5-1/6 *6.8)`

`f_1(x)=1.1333x^3-3.4x^2+6.2667x-3`, for `1<=x<=2`



Substitute `i=2` in equation `(1)`, we get cubic spline in `2^(nd)` interval `[x_1,x_2]=[2,3]`

`f_2(x)=(x_2-x)^3/(6h) M_1 + (x-x_1)^3/(6h) M_2 + ((x_2-x))/h (y_1-h^2/6 M_1)+((x-x_1))/h (y_2-h^2/6 M_2)`

`f_2(x)=(3-x)^3/6 *6.8 + (x-2)^3/6 *-15.2 + ((3-x))/1 (5-1/6 *6.8) + ((x-2))/1 (11-1/6 *-15.2)`

`f_2(x)=-3.6667x^3+25.4x^2-51.3333x+35.4`, for `2<=x<=3`



Substitute `i=3` in equation `(1)`, we get cubic spline in `3^(rd)` interval `[x_2,x_3]=[3,4]`

`f_3(x)=(x_3-x)^3/(6h) M_2 + (x-x_2)^3/(6h) M_3 + ((x_3-x))/h (y_2-h^2/6 M_2)+((x-x_2))/h (y_3-h^2/6 M_3)`

`f_3(x)=(4-x)^3/6 *-15.2 + (x-3)^3/6 *0 + ((4-x))/1 (11-1/6 *-15.2) + ((x-3))/1 (8-1/6 *0)`

`f_3(x)=2.5333x^3-30.4x^2+116.0667x-132`, for `3<=x<=4`



For `y(1.5)`, `1.5 in [1,2]`, so substitute `x=1.5` in `f_1(x)`, we get

`f_1(1.5)=2.575`

For `y'(2)`, `2 in [1,2]`, so find `f_1^(')(x)`

`f_1^(')(x)=3.4x^2-6.8x+6.2667`

Now substitute `x=2` in `f_1^(')(x)`, we get

`f_(1)^(')(2)=6.2667`


This material is intended as a summary. Use your textbook for detail explanation.
Any bug, improvement, feedback then Submit Here



1. Formula
(Previous example)
3. Example-2 (Fit 4 points)
(Next example)





Share this solution or page with your friends.


 
Copyright © 2024. All rights reserved. Terms, Privacy
 
 

.