<?xml version="1.0" encoding="UTF-8"?>
<Worksheet><Version major="6" minor="1"/><View-Properties><Zoom percentage="100"/></View-Properties><Styles><Layout alignment="left" bullet="none" firstindent="0.0" leftmargin="0.0" linebreak="space" linespacing="0.0" name="Normal" rightmargin="0.0" spaceabove="0.0" spacebelow="0.0"/><Font background="[0,0,0]" bold="true" executable="true" family="Monospaced" foreground="[255,0,0]" name="Maple Input" opaque="false" size="12"/><Font background="[0,0,0]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" name="Text" opaque="false" size="12" underline="false"/></Styles><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">#Written by Andrew Sommese, September 8, 2004</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">We can compute B-splines from scratch or use the built in Bspline commands.</Text-field><Text-field layout="Normal" style="Text">Usually we use the Bspline command, but we also do it from scratch.</Text-field><Text-field layout="Normal" style="Text">First from scratch.  We are using Maple 9.5. </Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input"/></Input></Group><Group><Input><Text-field layout="Normal" style="Text">First we recursively computes the k-th divided differences.</Text-field><Text-field layout="Normal" style="Text">Here w[0],...,w[k] are the knots and f is the function we are taking divided</Text-field><Text-field layout="Normal" style="Text">differences of.  </Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">divDiff := proc(w,k,f)  local j,u,v,kk;</Text-field></Input><Input><Text-field prompt="&gt; " style="Maple Input">if k=0 then f(w[0]); 
   else  kk:= k-1;</Text-field></Input><Input><Text-field prompt="&gt; " style="Maple Input">   for j from 0 to kk do 
            u[j]:= w[j]; 
            v[j]:= w[j+1]; 
                   od;</Text-field></Input><Input><Text-field prompt="&gt; " style="Maple Input">   (divDiff(v,kk,f)-divDiff(u,kk,f))/(v[kk]-u[0]);</Text-field></Input><Input><Text-field prompt="&gt; " style="Maple Input">fi:</Text-field></Input><Input><Text-field prompt="&gt; " style="Maple Input">end proc:</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input"/></Input></Group><Group><Input><Text-field layout="Normal" style="Text">Of course you might want to use a set of values, f[j] corresponding to w[j].</Text-field><Text-field layout="Normal" style="Text">This can be programmed by replacing f(w[0]) with f[0].</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input"/></Input></Group><Group><Input><Text-field layout="Normal" style="Text">Using the above we can define the order k B-spline. We do it in two forms.</Text-field><Text-field layout="Normal" style="Text">In the first form we assume that we have a knot sequence w[-k+1],...,w[n+k-1].</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">Bspln := proc(i,k,w,x) local g,v,j;</Text-field></Input><Input><Text-field prompt="&gt; " style="Maple Input">for j from 0 to k 
      do v[j]:=w[i+j]; 
      od;
g:= y -&gt; (v[k]-v[0])*max(0,y-x)^(k-1);</Text-field></Input><Input><Text-field prompt="&gt; " style="Maple Input">divDiff(v,k,g);</Text-field></Input><Input><Text-field prompt="&gt; " style="Maple Input">end proc;</Text-field></Input><Input><Text-field prompt="&gt; " style="Maple Input"/></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input"/></Input></Group><Group><Input><Text-field layout="Normal" style="Text">Let's check things out with the knots at the integers.</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">n:= 10;</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">k:= 5;</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">for j from -k+1 to n+k-1 do w[j]:= j; od:</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">plot(Bspln(1,5,w,x),x=-2..6);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">plot(sum(Bspln(ii,5,w,x),ii=-4..9)-1,x=0..10);#why is it ragged looking?</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input"/></Input></Group><Group><Input><Text-field layout="Normal" style="Text">In the second form we only use the knot sequence for the given B-spline (briefer name for briefer</Text-field><Text-field layout="Normal" style="Text">function.</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">Bspl := proc(k,w,x) local g,v,j;</Text-field></Input><Input><Text-field prompt="&gt; " style="Maple Input">for j from 0 to k 
      do v[j]:=w[j]; 
      od;
g:= y -&gt; (v[k]-v[0])*max(0,y-x)^(k-1);</Text-field></Input><Input><Text-field prompt="&gt; " style="Maple Input">divDiff(v,k,g);</Text-field></Input><Input><Text-field prompt="&gt; " style="Maple Input">end proc;</Text-field></Input><Input><Text-field prompt="&gt; " style="Maple Input"/></Input></Group><Group><Input><Text-field layout="Normal" style="Text">Let's check things out with the knots at the integers 1,2,3,4,5,6</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">for j from 0 to 5 do 
             w2[j]:= j+1; 
                  od:</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">plot(Bspl(5,w2,x),x=-2..7);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input"/></Input></Group><Group><Input><Text-field layout="Normal" style="Text">Now let's use builtin functions.  There are a number of variants.  I use the simplest variant--this is Bslpl above.</Text-field><Text-field layout="Normal" style="Text">We use the CurveFitting package.  Using Curvefitting; instead of CurveFitting: you can see the functions included</Text-field><Text-field layout="Normal" style="Text">in the package.  Use the help included in the software to look up examples of how the functions are used.</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">with(CurveFitting):</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">The following is equivalent to Bspl(5,w,x) above</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">BSpline(5, x, knots=[1,2,3,4,5,6]);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">Let's compute the difference!</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">plot(Bspl(5,w2,x)-BSpline(5, x, knots=[1,2,3,4,5,6]),x=-2..7);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">Of course, it is inconvenient to have to list the knots.  So you might try</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">BSpline(5, x, knots=w2);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">Maple is finicky.  It expects a list, not an array.  So let's give it a list.</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">ww:=convert(w2,'list');</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">Now let's try.</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">plot(BSpline(5,x,knots=ww),x=-2..7);</Text-field></Input></Group><Text-field/></Worksheet>