polyval function
Evaluates polynomial of degree N
2 N
y = C + C x + C x +...+ C x 0 1 2 N
Coefficients are stored in reverse order:
coef0 = C , ..., coefN = C .
N 0
polyval(5, [3,0,1]); // 3 * 5**2 + 0 * 5**1 + 1
>>> 76
Implementation
double polyval(num x, List<num> coef) {
final ite = coef.iterator;
ite.moveNext();
double ans = ite.current.toDouble();
while (ite.moveNext()) {
ans = ans * x + ite.current;
}
return ans;
}