#Written by Andrew Sommese, September 8, 2004We can compute B-splines from scratch or use the built in Bspline commands.Usually we use the Bspline command, but we also do it from scratch.First from scratch. We are using Maple 9.5. First we recursively computes the k-th divided differences.Here w[0],...,w[k] are the knots and f is the function we are taking divideddifferences of. divDiff := proc(w,k,f) local j,u,v,kk;if k=0 then f(w[0]);
else kk:= k-1; for j from 0 to kk do
u[j]:= w[j];
v[j]:= w[j+1];
od; (divDiff(v,kk,f)-divDiff(u,kk,f))/(v[kk]-u[0]);fi:end proc:Of course you might want to use a set of values, f[j] corresponding to w[j].This can be programmed by replacing f(w[0]) with f[0].Using the above we can define the order k B-spline. We do it in two forms.In the first form we assume that we have a knot sequence w[-k+1],...,w[n+k-1].Bspln := proc(i,k,w,x) local g,v,j;for j from 0 to k
do v[j]:=w[i+j];
od;
g:= y -> (v[k]-v[0])*max(0,y-x)^(k-1);divDiff(v,k,g);end proc;Let's check things out with the knots at the integers.n:= 10;k:= 5;for j from -k+1 to n+k-1 do w[j]:= j; od:plot(Bspln(1,5,w,x),x=-2..6);plot(sum(Bspln(ii,5,w,x),ii=-4..9)-1,x=0..10);#why is it ragged looking?In the second form we only use the knot sequence for the given B-spline (briefer name for brieferfunction.Bspl := proc(k,w,x) local g,v,j;for j from 0 to k
do v[j]:=w[j];
od;
g:= y -> (v[k]-v[0])*max(0,y-x)^(k-1);divDiff(v,k,g);end proc;Let's check things out with the knots at the integers 1,2,3,4,5,6for j from 0 to 5 do
w2[j]:= j+1;
od:plot(Bspl(5,w2,x),x=-2..7);Now let's use builtin functions. There are a number of variants. I use the simplest variant--this is Bslpl above.We use the CurveFitting package. Using Curvefitting; instead of CurveFitting: you can see the functions includedin the package. Use the help included in the software to look up examples of how the functions are used.with(CurveFitting):The following is equivalent to Bspl(5,w,x) aboveBSpline(5, x, knots=[1,2,3,4,5,6]);Let's compute the difference!plot(Bspl(5,w2,x)-BSpline(5, x, knots=[1,2,3,4,5,6]),x=-2..7);Of course, it is inconvenient to have to list the knots. So you might tryBSpline(5, x, knots=w2);Maple is finicky. It expects a list, not an array. So let's give it a list.ww:=convert(w2,'list');Now let's try.plot(BSpline(5,x,knots=ww),x=-2..7);