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)

6. Example-5 (Fit 5 points)
(Previous example)

7. Example-6 (Fit 5 points)





2. Calculate Cubic Splines
X12345
Y1251120
y(1.5)


Solution:
x12345
y1251120

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=4`

`M_0=0,M_4=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+M_3=6/1*(2-2*5+11)`

`=>M_1+4M_2+M_3=18`

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

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

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

`=>M_2+4M_3=18`

Solving these 3 equations using elimination method

Total Equations are `3`

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

`M_1+4M_2+M_3=18 -> (2)`

`0M_1+M_2+4M_3=18 -> (3)`



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

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




Select the equations `(3)` and `(4)`, and eliminate the variable `M_2`.

`M_2+4M_3=18`` xx 15->````15M_2``+``60M_3``=``270```
+
`-15M_2-4M_3=-60`` xx 1->``-``15M_2``-``4M_3``=``-60```

```56M_3``=``210`` -> (5)`




Now use back substitution method
From (5)
`56M_3=210`

`=>M_3=(210)/(56)=3.75`

From (3)
`M_2+4M_3=18`

`=>M_2+4(3.75)=18`

`=>M_2+15=18`

`=>M_2=18-15=3`

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

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

`=>M_1+15.75=18`

`=>M_1=18-15.75=2.25`

Solution using Elimination method.
`M_1=2.25,M_2=3,M_3=3.75`




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

`f_1(x)=0.375x^3-1.125x^2+1.75x`, 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.25 + (x-2)^3/6 *3 + ((3-x))/1 (2-1/6 *2.25) + ((x-2))/1 (5-1/6 *3)`

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

`f_3(x)=0.125x^3+0.375x^2-1.25x+2`, for `3<=x<=4`



Substitute `i=4` in equation `(1)`, we get cubic spline in `4^(th)` interval `[x_3,x_4]=[4,5]`

`f_4(x)=(x_4-x)^3/(6h) M_3 + (x-x_3)^3/(6h) M_4 + ((x_4-x))/h (y_3-h^2/6 M_3)+((x-x_3))/h (y_4-h^2/6 M_4)`

`f_4(x)=(5-x)^3/6 *3.75 + (x-4)^3/6 *0 + ((5-x))/1 (11-1/6 *3.75) + ((x-4))/1 (20-1/6 *0)`

`f_4(x)=-0.625x^3+9.375x^2-37.25x+50`, for `4<=x<=5`



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.3594`


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



6. Example-5 (Fit 5 points)
(Previous example)





Share this solution or page with your friends.


 
Copyright © 2024. All rights reserved. Terms, Privacy
 
 

.