3 ms·
A little ASCII art for math from a code snippet of mine: // // B(m,n)(x) = binomial(m
by waynecochran 8y ago
A little ASCII art for math from a code snippet of mine:
//
// B(m,n)(x) = binomial(m,n) * (1-x)^(m-n) * x^n
// __ m-n
// (1-x)^(m-n) = \ (-1)^i * binomial(m-n,i) * x^i
// /_ i=0
// __ m-n
// B(m,n)(x) = binomial(m,n) \ (-1)^i * binomial(m-n,i) * x^(i+n)
// /_ i=0
//
Polynomial Polynomial::bernstein(unsigned m, unsigned n) {
Polynomial B(m);
unsigned j = m-n;
double scale = binomial(m,n);
for (unsigned i = 0; i <= j; i++)
if (isEven(i))
B[i+n] = scale*binomial(j,i);
else
B[i+n] = -scale*binomial(j,i);
return B;
}
- AnaniasAnanas 8y agoI just use latex for things like that in my comments.
- sn41 8y agoMaxima[1] can do symbolic computation and display the result in ASCII. I use Maxima notation when I need to do this. [1] https://en.wikipedia.org/wiki/Maxima_(software) https://en.wikipedia.org/wiki/Maxima_(software)