(*  bernstein_poly_values.nb *)
(* *)
(*  Purpose: *)
(*    Evaluate the Bernstein polynomials *)
(*    of selected orders n and argument values, *)
(*    and write the data to a file. *)
(* *)
(*  Modified:  02 December 2005 *)
(*  Author:  John Burkardt *)

nvec = {0,1,1,2,2,2,3,3,3,3,4,4,4,4,4}
kvec={0,0,1,0,1,2,0,1,2,3,0,1,2,3,4}
xvec={1/4,1/4,1/4,1/4,1/4,1/4,1/4,1/4,1/4,1/4,1/4,1/4,1/4,1/4,1/4}
fvec = {}
num = Length [ nvec ]

Do [ {
 n= nvec[[i]],
 k=kvec[[i]],
x=xvec[[i]],f = Binomial[n,k]*(1-x)^(n-k)*x^k ,
fvec = Append [ fvec, f ],
      Print["  B[",n,",",k,",",x,"]=",N[f,16]] },{i,1,num,1}]

fileout=OpenWrite["/Users/burkardt/public_html/math_src/test_values/bernstein_poly_values.txt"];
SetOptions[fileout,FormatType->TextForm];
Write[fileout,"#  bernstein_poly_values.txt"];today=DateList[];Write[fileout,"#  Created on ",today];Write[fileout,"#"];
Write[fileout,"#  n k x fx"];
Write[fileout,"#"];
Do[{n=nvec[[i]],k=kvec[[i]],x=xvec[[i]];f=fvec[[i]];Write[fileout,N[n,16],"  ",N[k,16],"  ",N[x,16],"  ",N[f,16]]},{i,1,num,1}];Close[fileout];