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

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

Begin["Private`"]
 
errprod[x_,t_] := N[Product[t-x[[i]],{i,1,Length[x]}]/(Length[x]+1)!]

a=-5
b=5
n=8

pts[z_] := Join[{a,-z},Table[a+j(b-a)/n,{j,2,n-2}],{z,b}]

max[p_] := Max[Table[errprod[p,t],{t,a,b,(b-a)/100}]]

min[p_] := Min[Table[errprod[p,t],{t,a,b,(b-a)/100}]]

point[x_]:=Point[{x,0}]

SetAttributes[point,Listable]

plot[p_]:=Plot[errprod[p,t],{t,-5,5},
          PlotRange -> {{-6,6},{-.012,.012}}, 
          PlotStyle -> {{Thickness[0.01], Green}},AspectRatio->1,
          Background->Black,DefaultColor->White,
          Epilog->Join[{Red,PointSize[.02]},point[p]],
          DisplayFunction->Identity]

cpts[s_] := (1-s) Table[a+j(b-a)/n,{j,0,n}]- 
        s Table[(a+b)/2 + (b-a)/2Cos[(2j-1)Pi/(2n+2)],{j,1,n+1}] 
        
plotwithlines[p_] := Plot[errprod[p,t],{t,-5,5},
          PlotRange -> {{-6,6},{-.012,.012}}, 
          PlotStyle -> {{Thickness[0.01], Green}},AspectRatio->1,
          Background->Black,DefaultColor->White,
          Epilog->Join[{Red,PointSize[.02]},point[p],
            {Line[{{a,max[p]},{b,max[p]}}],Line[{{a,min[p]},{b,min[p]}}]}],
          DisplayFunction->Identity]
          
          
 ShowAnimation[Table[plot[pts[z]],{z,15/4,19/4,1/12}],
  AnimationFunction->(DisplayAnimation["errprod.anim",#]&)];

Print["-- wrote file errprod.anim --"]
          
 ShowAnimation[Table[plotwithlines[cpts[s]],{s,0,1,1/10}],
  AnimationFunction->(DisplayAnimation["errprodc.anim",#]&)];

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

End[] (* end of context private *)

EndPackage[]

