Divide the x interval [α,β]=[-2,2] into three ordered points (-2,0.2), (1,0.5), (2,0.2). So n=3. Refer to these as (x0,y0), (x1,y1), (x2,y2). The question doesn't specify the number of splines (interpolants), so as an illustration I'll just use 2 (that is, n-1), which are splines between (-2,0.2) and (1,0.5) (knot), and (1,0.5) and (2,0.2). (In general, for n data points there would be n-1 splines and n-2 knots.)
A cubic spline: Si(x)=ai+bi(x-xi)+ci(x-xi)2+di(x-xi)3 where i=0, 1, or 2 in this example. The splines must pass through the 3 given points. Therefore we have:
S0(x)=a0+b0(x-x0)+c0(x-x0)2+d0(x-x0)3=f(x0)=y0 for x∈[x0,x1];
S1(x)=a1+b1(x-x1)+c1(x-x1)2+d1(x-x1)3=f(x1)=y1 for x∈[x1,x2];
S2(x)=a2+b2(x-x2)+c2(x-x2)2+d2(x-x2)3=f(x2)=y2 for x≥x2.
These are the pieces of the piecewise function S(x). We have 12 (=4n) unknown coefficients here, so we need to find more conditions to satisfy the equations. For the required condition of continuity, the end-point of the first interval is also the start-point of the second interval:
S0(x1)=S1(x1)=f(x1)=f(1)=y1=0.5 and, similarly for the end-point of the second interval and (β,f(β)): S1(x2)=S2(x2)=f(x2)=f(2)=y2=0.2=f(β).
Also: S0(x0)=S0(α)=S0(-2)=f(-2)=y0=0.2.
We can now partly solve for these unknowns:
S0(x)=a0+b0(x-x0)+c0(x-x0)2+d0(x-x0)3 at (-2,0.2) becomes:
S0(-2)=a0=f(-2)=y0=0.2, so a0=0.2, because x0-x0=0. Also:
S2(2)=a2=f(2)=y2=0.2, so a2=0.2.
S1(1)=a1=f(1)=y1=0.5, so a1=0.5.
S0(1)=S1(1)=0.5⇒S0(1)=0.2+3b0+9c0+27d0=0.5.
S1(2)=S2(2)=0.2⇒S1(2)=0.5+b1+c2+d2=0.2.
Now we turn to the "smoothness" of the knot. This involves another condition, that the first derivatives are equal at common points on the splines. In this example there's only one common point at (1,0.5).
S0'(1)=S1'(1) and S1'(2)=S2'(2).
S0'(x)=b0+2c0(x-x0)+3d0(x-x0)2
S1'(x)=b1+2c1(x-x1)+3d1(x-x1)2
S2'(x)=b2+2c2(x-x2)+3d2(x-x2)2
The second derivative is used to equate the curvature at the knot.
S0"(1)=S1"(1) and S1"(2)=S2"(2).
S0"(x0)=2c0+6d0(x-x0)
S1"(x1)=2c1+6d1(x-x1)
S2"(x2)=2c2+6d2(x-x2)
Another condition distinguishes natural splines from clamped splines and enables us to find all the coefficients. This condition applies specifically to the end-points of the encompassing interval [α,β].
For clamped cubic splines we need the first derivatives at the end-points (α,f(α)) and (β,f(β)). We can only work out all the coefficients if we know f'(α) and f'(β). f'(x)=-2x/(1+x2)2; f'(-2)=4/25=0.16; f'(2)=-4/25=-0.16, because we know f(x)=1/(1+x2), just as we knew f(x) for x=-2, 1, 2=0.2, 0.5, 0.2. For natural cubic splines we only have to know that the second derivatives are zero at the end-points (α,f(α)) and (β,f(β)).
S0'(-2)=b0=f'(-2)=0.16, so b0=0.16; and S2'(2)=b2=f'(2)=-0.16. So we now have all ai, b0 and b2. We need b1, all ci and all di (7 coefficients). Using all the conditions and making substitutions for known coefficients, we have:
S0(1)=S1(1): 0.2+0.48+9c0+27d0=0.5;
S1(2)=S2(2): 0.5+b1+c1+d1=0.2;
S0'(1)=S1'(1): 0.16+2c0(1+2)+3d0(1+2)2=0.16+6c0+27d0=b1;
S1'(2)=S2'(2): b1+2c1+3d1=-0.16;
S0"(1)=S1"(1): 2c0+6d0(1+2)=2c0+18d0=2c1;
S1"(2)=S2"(2): 2c1+6d1=2c2 (to be omitted).
But we have no use for c2 or d2 because we don't need a spline for anything beyond x=β, a2 was only used in S1(2)=S2(2), and b2 was only used in S1'(2)=S2'(2). So the last second derivative equation (containing c2) can be omitted. That leaves 5 equations and 5 unknown coefficients: b1, c0, c1, d0, d1. We have all we need. We can solve using a 5×5 matrix A or elimination and substitution.
Matrix A=
⎛ 0 9 0 27 0 ⎞
⎜ 1 0 1 0 1 ⎟
⎟ 1 -6 0 -27 0 ⎟
⎜ 1 0 2 0 3 ⎟
⎝ 0 2 -2 18 0 ⎠
Matrix X=
⎛ b1 ⎞
⎜c0 ⎜
⎜c1 ⎟
⎜ d0 ⎜
⎝ d1 ⎠
and B=
⎛ -0.18 ⎞
⎜ -0.30 ⎟
⎜ 0.16 ⎟
⎜-0.16 ⎟
⎝ 0 ⎠
We solve for X in AX=B.
d0=-(0.18+9c0)/27=-(0.02+c0)/3,
b1-6c0+0.18+9c0=0.16, b1=-0.02-3c0,
c1=c0-(0.18+9c0)/3=-2c0-0.6,
d1=-0.3+0.02+3c0+2c0+0.6=5c0+0.32,
-0.02-3c0-4c0-1.2+15c0+0.96=-0.16, 8c0=-0.16+0.02+1.2-0.96=0.1, c0=0.0125.
Therefore: d0=-13/1200=-0.01083 approx; b1=-0.0575; c1=-0.625; d1=0.3825.
S0(x)=0.2+0.16(x+2)+0.0125(x+2)2-(13/1200)(x+2)3,
S1(x)=0.5-0.0575(x-1)-0.625(x-1)2+0.3825(x-1)3.