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)

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

3. Example-2 (Fit 4 points)





2. Calculate Cubic Splines
X1234
Y12511
y(1.5), y'(3)


Solution:
x1234
y12511

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*2+5)`

`=>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*(2-2*5+11)`

`=>M_1+4M_2=18`

Solving these 2 equations using elimination method

Total Equations are `2`

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

`M_1+4M_2=18 -> (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=18`` xx 4->````4M_1``+``16M_2``=``72```

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




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

`=>M_2=(-60)/(-15)=4`

From (2)
`M_1+4M_2=18`

`=>M_1+4(4)=18`

`=>M_1+16=18`

`=>M_1=18-16=2`

Solution using Elimination method.
`M_1=2,M_2=4`




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 *2 + ((2-x))/1 (1-1/6 *0) + ((x-1))/1 (2-1/6 *2)`

`f_1(x)=1/3(x^3-3x^2+5x)`, 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 *2 + (x-2)^3/6 *4 + ((3-x))/1 (2-1/6 *2) + ((x-2))/1 (5-1/6 *4)`

`f_2(x)=1/3(x^3-3x^2+5x)`, 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 *4 + (x-3)^3/6 *0 + ((4-x))/1 (5-1/6 *4) + ((x-3))/1 (11-1/6 *0)`

`f_3(x)=1/3(-2x^3+24x^2-76x+81)`, 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)=1.375`

For `y'(3)`, `3 in [2,3]`, so find `f_2^(')(x)`

`f_2^(')(x)=1/3(3x^2-6x+5)`

Now substitute `x=3` in `f_2^(')(x)`, we get

`f_(2)^(')(3)=4.6667`


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



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





Share this solution or page with your friends.


 
Copyright © 2024. All rights reserved. Terms, Privacy
 
 

.