MATLAB spline interpolation example x x = 0 1.0000 2.0000 2.5000 3.0000 3.5000 4.0000 y y = 2.5000 0.5000 0.5000 1.5000 1.5000 1.1250 0 xx=0:.01:4; yy=spline(x,y,xx); plot(x,y,':',xx,yy) pp=spline(x,y); [breakpts,coeffs,L,K]=unmkpp(pp); whos Name Size Elements Bytes Density Complex K 1 by 1 1 8 Full No L 1 by 1 1 8 Full No breakpts 1 by 7 7 56 Full No coeffs 6 by 4 24 192 Full No pp 1 by 35 35 280 Full No x 1 by 7 7 56 Full No xx 1 by 401 401 3208 Full No y 1 by 7 7 56 Full No yy 1 by 401 401 3208 Full No Grand total is 916 elements using 7328 bytes breakpts breakpts = 0 1.0000 2.0000 2.5000 3.0000 3.5000 4.0000 L L = 6 K K = 4 coeffs coeffs = 0.4225 -0.2674 -2.1550 2.5000 0.4225 1.0000 -1.4225 0.5000 -3.9147 2.2674 1.8450 0.5000 2.5039 -3.6047 1.1764 1.5000 -1.1008 0.1512 -0.5504 1.5000 -1.1008 -1.5000 -1.2248 1.1250 To better understand the elements of coefficient, we will include the left and right breakpoints (xl and xr) for each row and label each column xl xr a3 a2 a1 a0 0.0 1.0 0.4225 -0.2674 -2.1550 2.5000 1.0 2.0 0.4225 1.0000 -1.4225 0.5000 2.0 2.5 -3.9147 2.2674 1.8450 0.5000 2.5 3.0 2.5039 -3.6047 1.1764 1.5000 3.0 3.5 -1.1008 0.1512 -0.5504 1.5000 3.5 4.0 -1.1008 -1.5000 -1.2248 1.1250 The spline function s(x) on the interval [xl,xr] is defined by s(x) = a0 + a1*(x-xl) + a2*(x-xl)^2 + a3*(x-xl)^3 = a0 + (x-xl)*[a1 + (x-xl)*[a2 + (x-xl)*a3]] with x in the interval [xl,xr]. In the above example, s(x) is defined on the interval [3.5,4] by the expression s(x) = 1.125 - 1.2248*(x-3.5) - 1.5*(x-3.5)^2 - 1.1008*(x-3.5)^3 Thus on [3.5,4], for example, s'(x) = -1.2248 - 3.0*(x-3.5) - 3.3024*(x-3.5)^2 s''(x) = -3.0 - 6.6048*(x-3.5) s(3.5)=1.125, s'(3.5)=-1.2248, s''(3.5)=-3.0 s(4.0)=0, s'(4)=-3.5504, s''(4)=-6.3024 On the interval [3.0,3.5], s(x) = 1.5 - 0.5504*(x-3) + 0.1512*(x-3)^2 - 1.1008*(x-3)^3 s'(x) = - 0.5504 + 0.3024*(x-3) - 3.3024*(x-3)^2 s''(x) = 0.3024 - 6.6048*(x-3) From this formula, s(3.5)=1.125, s'(3.5)=-1.2248, s''(3.5)=-3.0 Note the agreement with the values of s(x) from the interval [3.5,4].