value of Bernstein polynomial


//============================================================================
// Name        : Bernstein.cpp
// Author      : chd
// Version     :
// Copyright   : Your copyright notice
// Description : This simple function computes the value of a Bernstein polynomial, C++ Ansi-style
//============================================================================

#include <iostream>
using namespace std;

double Bernstein(int i,int n,double u);

int main() {

	double res=0;
	res=Bernstein(1,1,0.5);
}


double Bernstein(int i, int n, double u){

	double *temp=new double[n+1];

	for (int j = 0; j <= n; ++j) {

		temp[j]=0.0;
	}

	temp[n-i]=1.0;
	double u1=1.0-u;

	for (int k = 1; k <= n; ++k) {

		for (int j = n; j >=k; --j) {

			temp[j]=u1*temp[j]+u*temp[j-1];

		}
	}

	cout<<"B"<<i<<n<<"("<<u<<")"<<":"<<temp[n];
	return temp[n];


}