MAPLE: Cubic Spline Interpolants Code error
<p>I am writing code to compute the cubic splines interpolants using n+1 equally spaced interpolation points between -1 and 2 (taking n=6 and n=10), plotting the graphs against f(x) and finding the max error. I get no errors for the code for n=6 although I am unsure if the max error is correct. When I use the same code altered for n=10, it doesn't appear to work. Help would be appreciated.</p>

<p>Here is my code:
n=6.</p>

<pre><code>restart;

f := proc (x) options operator, arrow; (1-x^2)*sin(2*Pi*x);

Xlist := [-1, -.5, 0, .5, 1, 1.5, 2];

k := nops(Xlist);

for i to k-1 do 
  S[i] := a[i]+b[i]*(x-Xlist[i])+c[i]*(x-Xlist[i])^2+d[i]*(x-Xlist[i])^3;
  dS[i] := diff(S[i], x);
  ddS[i] := diff(dS[i], x;
end do;

for i from 1 to k-1 do 
EQ[i] := subs(x = Xlist[i], S[i]) = f(Xlist[i]);
 end do;

for i from 1 to k-1 do 
EQ[k-1+i] := subs(x = Xlist[i+1], S[i]) = f(Xlist[i+1]);
end do;

for i from 1 to k-2 do
EQ[2*k-2+i] := subs(x = Xlist[i+1], dS[i]) = subs(x = Xlist[i+1], dS[i+1]);
end do;

for i from 1 to k-2 do
EQ[3*k-4+i] := subs(x = Xlist[i+1], ddS[i]) = subs(x = Xlist[i+1], ddS[i+1]);
end do;

Clamp[1] := subs(x = Xlist[1], dS[1]) = (D(f))(Xlist[1]);

Clamp[2] := subs(x = Xlist[k], dS[k-1]) = (D(f))(Xlist[k]);

ClampedEqs := {Clamp[1], Clamp[2], seq(EQ[i], i = 1 .. 4*k-6)};

ClampedCoeffs := op(1, solve(ClampedEqs, [seq(a[i], i = 1 .. k-1), seq(b[i], i = 1 .. k-1), seq(c[i], i = 1 .. k-1), seq(d[i], i = 1 .. k-1)]));

assign(ClampedCoeffs)
ClampedSpline := proc (x) options operator, arrow; piecewise(x &lt; Xlist[2], S[1], S[2]);

plot([f(x), ClampedSpline(x)], x = -1 .. 2);

print(Max*Error*is = numapprox[infnorm](f(x)-ClampedSpline(x), x = -1 .. 2));                                                                          
</code></pre>

<p>which gives max error 5.146099863</p>

<p>However when I change to n=10, after the 'ClampedEqs@ op I get "Error, improper op or subscript selector" error where I didn't before.</p>