Previous Up Next

11.2.3 Natural interpolation

The spline command finds the natural spline.

Examples

Find the natural spline of degree 3, crossing through the points x0=0,y0=1, x1=1,y1=3 and x2=2, y2=0.

spline([0,1,2],[1,3,0],x,3)
     
⎡
⎢
⎢
⎣
−
5
4
 x3+
13
4
 x+1,
5
4
 ⎛
⎝
x−1⎞
⎠
3−
15
4
 ⎛
⎝
x−1⎞
⎠
2−
x−1
2
+3⎤
⎥
⎥
⎦
          

Where the first polynomial, −5/4 x3+13/4 x+1, is defined on the interval [0,1] (the first interval defined by the list [0,1,2]) and the second polynomial 5/4 (x−1)3−15/4 (x−1)2−x−1/2+3 is defined on the interval [1,2], the second interval defined by the list [0,1,2].

Find the natural spline of degree 4, crossing through the points x0=0,y0=1, x1=1,y1=3, x2=2, y2=0 and x3=3, y3=−1.

spline([0,1,2,3],[1,3,0,-1],x,4)
     
⎡
⎢
⎢
⎢
⎣
−
62
121
 x4+
304
121
 x+1,
         
 
201
121
⎛
⎝
x−1⎞
⎠
4−
248
121
⎛
⎝
x−1⎞
⎠
3−
372
121
⎛
⎝
x−1⎞
⎠
2+
56
121
⎛
⎝
x−1⎞
⎠
+3,
         
−
139
121
 ⎛
⎝
x−2⎞
⎠
4+
556
121
 ⎛
⎝
x−2⎞
⎠
3+
90
121
 ⎛
⎝
x−2⎞
⎠
2−
628
121
 ⎛
⎝
x−2⎞
⎠
⎤
⎥
⎥
⎥
⎦
         

Output is a list of three polynomial functions of x, defined respectively on the intervals [0,1], [1,2] and [2,3].

Find the natural spline interpolation of cos on [0,π/2,3π/2].

spline([0,pi/2,3*pi/2],cos([0,pi/2,3*pi/2]),x,3)
     
⎡
⎢
⎢
⎢
⎣
4 x3
3 π 3
−
7 x
3 π 
+1, −
2 ⎛
⎜
⎜
⎝
x−
π 
2
⎞
⎟
⎟
⎠
3



 
3 π 3
+
2 ⎛
⎜
⎜
⎝
x−
π 
2
⎞
⎟
⎟
⎠
2



 
π 2
−
4 ⎛
⎜
⎜
⎝
x−
π
2
⎞
⎟
⎟
⎠
3 π 
⎤
⎥
⎥
⎥
⎦
          

Previous Up Next