问题
A while ago I implemented a Polynom approximation for a game I programmed.
I am using Newton's pyramide method. It took me quite a while to figure it out, but my solution requires to calculate the binomial coefficients and I also have to sum up all the coefficients for the final coefficient of each power (since solving this problem is similar to squaring, cubing.. terms and calculating the binomial coefficients)
For example:
pick k out of n of the bionomeal terms and add them
one pick is multiplied
a*(x+b)(x+c)(x+d) ==> a*x^3 + a*x^2*(b+c+d) + a*x(bc+bd+cd) +a*b*c*d
so b*c*d would be one pick b*c and b*d too
My question now is: Is there a way calculating the Polynominterpolation with the newton scheme without having to calculate all the bionomial coefficients?
My code: https://github.com/superphil0/Polynominterpolation/blob/master/PolynomInterpolation.java
It works pretty good, although if one gives too many points it will be rather slow because of the selection of terms which have all be summed up
(I am really bad at explaining this in english, I hope someone can understand what I want to know though)
cheers
回答1:
Judging from this description, I take it that your “pyramid scheme” generates coefficients ci such that the polynomial p(x) can be written as
p(x) =
c0 + (x ‒ x0)(
c1 + (x ‒ x1)(
c2 + (x ‒ x2)(
c3 + (x ‒ x3)(
… (
cn-1 + (x ‒ xn‒1)
cn ) … ))))
Now you can compute canonical coefficients recursively from the back. Start with
pn = cn
In every step, the current polynomial can be written as
pk =
ck + (x ‒ xk)pk+1 =
ck + (x ‒ xk)(b0 +
b1x + b2x2 + …)
assuming that the next smaller polynomial has already been turned into canonical coefficients.
Now you can compute the coefficients ai of pk using those coefficients bi of pk+1. In a strict formal way, I'd have to use indices instead of a and b, but I believe that it's clearer this way. So what are the canonical coefficients of the next polynomial?
- a0 = ck − xkb0
- a1 = b0 − xkb1
- a2 = b1 − xkb2
- …
You can write this in a loop, using and reusing a single array a
to hold the coefficients:
double[] a = new double[n + 1]; // initialized to zeros
for (int k = n; k >= 0; --k) {
for (int i = n - k; i > 0; --i)
a[i] = a[i - 1] - x[k]*a[i];
a[0] = c[k] - x[k]*a[0];
}
来源:https://stackoverflow.com/questions/13435257/canonical-coefficients-from-newton-polynomial