I've got a Multinomial
class with private:
unsigned int power;
double *factors;
I'd like to know if there is more efficient way to calculate multinomial's result for given argument?
My current code is:
double Multinomial::calculateFor(double x) const{
double sum = this->factors[0];
double prod = 1;
for(size_t i = 1; i <= this->power; i++){
prod *= x;
if(this->factors[i]){
sum += this->factors[i] * prod;
}
}
return sum;
}