Bernstein Polynomials

(Subscript[B, i]^n)(t) = ( ({{n}, {i}}) ) (((1-t))^(n-i))(t^i)

Recall Pascal’s triangle: (contains powers of t, (1-t) )

1
1   1
1   2   1
1   3   3   1
1  4    6   4   1
1   5  10  10  5   1
	...

Recursion

bern[n_,i_,t_]:=If[i< 0||i> n,0.0,If[n==0,1.0,(1-t)*bern[n-1,i,t]+t*bern[n-1,i-1,t]]];
bernbasis[n_,t_]:=Table[bern[n,i,t],{i,0,n}];

dca[bb_,r_,i_,t_]:=If [r==0,bb[[i+1]],(1-t)*dca[bb,r-1,i,t]+t*dca[bb,r-1,i+1,t]];

Bernstein/Bezier Curve :

b={{0,0,-1},{1,1,1},{1,0,0},{0,1,1}};
n=Length[b]-1;
curve[b_,t_]:=Sum[b[[i+1]]*bern[n,i,t],{i,0,n}];
bezcurv=ParametricPlot3D[curve[b,t],{t,0,1},Axes->False,PlotStyle->Thick];
poly=Graphics3D[{Thick,Green,Line[b]}];

points=Graphics3D[{PointSize[Large],Point[b]}];
begin= Graphics3D[{PointSize[Large],Red,Point[b[[1]]]}];
Show[{poly,points,bezcurv,begin},Boxed->False]

Plot[bernbasis[7,t],{t,0,1},PlotRange-> All]

Explicit Definition

bernex[n_,i_,t_]:=Binomial[n,i]*(1-t)^(n-i)*t^i;
bernexbasis[n_,t_]:=Table[bernex[n,i,t],{i,0,n}];
Plot[bernexbasis[7,t],{t,0,1},PlotRange-> All]

Mathematica Definition

bernmathbasis[n_,t_]:=Table[BernsteinBasis[n,i,t],{i,0,n}];
Plot[bernmathbasis[7,t],{t,0,1},PlotRange-> All]

Timing

berntable=Table[(btime=Timing[bernbasis[n,0.5]];btime[[1]]),{n,1,7}];
bernextable=Table[(btime=Timing[bernexbasis[n,0.5]];btime[[1]]),{n,1,7}];
bernmathtable=Table[(btime=Timing[bernmathbasis[n,0.5]];btime[[1]]),{n,1,7}];

dcatimes=Table[First[Timing[dca[b,i,0,0.5]]],{i,2,4}];

ListPlot[dcatimes,PlotRange-> All, Filling-> Axis,Joined-> True,PlotStyle-> Thick]