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)

5. Example-4 (Fit 3 points)
(Previous example)
7. Example-6 (Fit 5 points)
(Next example)

6. Example-5 (Fit 5 points)





1. Calculate Cubic Splines
X12345
Y01010
y(1.5)


Solution:
x12345
y01010

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

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

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

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

`=>M_2+4M_3=-12`

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=12 -> (2)`

`0M_1+M_2+4M_3=-12 -> (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=12`` xx 4->````4M_1``+``16M_2``+``4M_3``=``48```

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




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

`M_2+4M_3=-12`` xx 15->````15M_2``+``60M_3``=``-180```
+
`-15M_2-4M_3=-60`` xx 1->``-``15M_2``-``4M_3``=``-60```

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




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

`=>M_3=(-240)/(56)=-4.2857`

From (3)
`M_2+4M_3=-12`

`=>M_2+4(-4.2857)=-12`

`=>M_2-17.1429=-12`

`=>M_2=-12+17.1429=5.1429`

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

`=>M_1+4(5.1429)+(-4.2857)=12`

`=>M_1+16.2857=12`

`=>M_1=12-16.2857=-4.2857`

Solution using Elimination method.
`M_1=-4.2857,M_2=5.1429,M_3=-4.2857`




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

`f_1(x)=-0.7143x^3+2.1428x^2-0.4286x-1`, 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 *-4.2857 + (x-2)^3/6 *5.1429 + ((3-x))/1 (1-1/6 *-4.2857) + ((x-2))/1 (0-1/6 *5.1429)`

`f_2(x)=1.5714x^3-11.5714x^2+27x-19.2857`, 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 *5.1429 + (x-3)^3/6 *-4.2857 + ((4-x))/1 (0-1/6 *5.1429) + ((x-3))/1 (1-1/6 *-4.2857)`

`f_3(x)=-1.5714x^3+16.7144x^2-57.8574x+65.5718`, 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 *-4.2857 + (x-4)^3/6 *0 + ((5-x))/1 (1-1/6 *-4.2857) + ((x-4))/1 (0-1/6 *0)`

`f_4(x)=0.7143x^3-10.7142x^2+51.857x-80.714`, 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)=0.7679`


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



5. Example-4 (Fit 3 points)
(Previous example)
7. Example-6 (Fit 5 points)
(Next example)





Share this solution or page with your friends.


 
Copyright © 2024. All rights reserved. Terms, Privacy
 
 

.