(* author: Douglas N. Arnold, dna@math.psu.edu, 11/96 *)

BeginPackage["Absinterp`", "Graphics`Animation`", "Graphics`Colors`"]

Begin["Private`"]
 
absint[n_,x_] :=
(InterpolatingPolynomial[Table[{x,Abs[x]},{x,-1,1,2/n}],tt] /. tt->x)

c[j_,n_] := N[Cos[(2j-1)Pi/(2n)]]

absintc[n_,x_] := 
(InterpolatingPolynomial[Table[{c[j,n+1],Abs[c[j,n+1]]},{j,1,n+1}],tt] /. tt->x)

absintplot[n_]:= Plot[Release[{Abs[t],absint[n,t]}],{t,-1,1},
  PlotPoints->100,
  PlotRange->{{-1,1},{-.5,1.5}},
  PlotStyle->{{Thickness[.005],Yellow},{Thickness[.01],Green}},
  Background->Black,DefaultColor->White,AspectRatio->Automatic,
  Ticks -> None,
  Epilog->{Red,PointSize[.02],Table[Point[{x,Abs[x]}],{x,-1,1,2/n}],
           Yellow,Text[FontForm[
                 StringJoin["deg = ",ToString[n]],
                   {"Helvetica-Bold",24}],Scaled[{.325,.9}],{-1,0}]
           },
  DisplayFunction->Identity]

absintcplot[n_]:= Plot[Release[{Abs[t],absintc[n,t]}],{t,-1,1},
  PlotPoints->100,
  PlotRange->{{-1,1},{-.5,1.5}},
  PlotStyle->{{Thickness[.005],Yellow},{Thickness[.01],Green}},
  Background->Black,DefaultColor->White,AspectRatio->Automatic,
  Ticks -> None,
  Epilog->{Red,PointSize[.02],Table[Point[{c[j,n+1],Abs[c[j,n+1]]}],{j,1,n+1}],
           Yellow,Text[FontForm[
                 StringJoin["deg = ",ToString[n]],
                   {"Helvetica-Bold",24}],Scaled[{.325,.9}],{-1,0}]
           },
  DisplayFunction->Identity]

(* Create the animations. *)

frameno = {2,4,6,8,12,16,24,32,48}

ShowAnimation[Table[absintplot[frameno[[n]]],{n,1,Length[frameno]}],
  AnimationFunction->(DisplayAnimation["absint.anim",#]&)];

Print["-- wrote file absint.anim --"]

ShowAnimation[Table[absintcplot[frameno[[n]]],{n,1,Length[frameno]}],
  AnimationFunction->(DisplayAnimation["absintc.anim",#]&)];

Print["-- wrote file absintc.anim --"]

End[] (* end of context private *)

EndPackage[]

