Construction

Let us now try to construct the cubic spline interpolant:

> restart:

> S[j]:=xx->a[j]+b[j]*(xx-x[j])+c[j]*(xx-x[j])^2+d[j]*(xx-x[j])^3;

[Maple Math]

> eq1:=subs(xx=x[j],S[j](xx))=f(x[j]);

[Maple Math]

> eq2:=a[j+1]=S[j](x[j+1]);

[Maple Math]

> eq2a:=subs(x[j+1]=h[j]+x[j],eq2);

[Maple Math]

> D(S[j])(xx);

[Maple Math]

> subs(xx=x[j],D(S[j])(xx));

[Maple Math]

> eq4:=b[j+1]=D(S[j])(x[j+1]);

[Maple Math]

> eq4a:=subs(x[j+1]=h[j]+x[j],eq4);

[Maple Math]

> (D@@2)(S[j])(xx);

[Maple Math]

> subs(xx=x[j],(D@@2)(S[j])(xx));

[Maple Math]

> eq5:=2*c[j+1]=(D@@2)(S[j])(x[j+1]);

[Maple Math]

> eq5a:=subs(x[j+1]=h[j]+x[j],eq5/2);

[Maple Math]

> dj:=solve(eq5a,d[j]);

[Maple Math]

> eq2b:=simplify(subs(d[j]=dj,eq2a));

[Maple Math]

> eq4b:=simplify(subs(d[j]=dj,eq4a));

[Maple Math]

> bj:=simplify(solve(eq2b,b[j]));

[Maple Math]

> bjmin:=simplify(subs(j=j-1,bj));

[Maple Math]

> eq4c:=subs(j=j-1,eq4b);

[Maple Math]

> eqf:=simplify(subs(b[j]=bj,b[j-1]=bjmin,eq4c));

[Maple Math]

> eqf1:=simplify(lhs(eqf)+(1/3)*(-3*a[j+1]+3*a[j])/h[j]=rhs(eqf)+(1/3)*(-3*a[j+1]+3*a[j])/h[j]);

[Maple Math]

> eqf2:=simplify(lhs(eqf1)-(1/3)*(c[j-1]*h[j-1]^2+2*h[j-1]^2*c[j])/h[j-1]=rhs(eqf1)-(1/3)*(c[j-1]*h[j-1]^2+2*h[j-1]^2*c[j])/h[j-1]);

[Maple Math]

All [Maple Math] 's are known so we should be able to solve this system for the coefficients [Maple Math] . Let us consider this system in a practical case:

> for i from 1 to 4 do eqq[i]:=subs(j=i,eqf2): od;

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

add the two boundary conditions:

> eqq[0]:=c[0]=0;eqq[5]:=c[5]=0;

[Maple Math]

[Maple Math]

Which consitutes a system of linear equations, with coefficient matrix

> with(linalg):AA:=genmatrix([eqq[0],eqq[1],eqq[2],eqq[3],eqq[4],eqq[5]],[c[0],c[1],c[2],c[3],c[4],c[5]]);

[Maple Math]

One can show that a matrix of this form will lead to a unique solution of the system, so that a unique spline exists.

>

>