From: Michael Orlitzky Date: Fri, 26 Oct 2012 18:13:03 +0000 (-0400) Subject: Add the divided_difference_coefficients() function. X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=0594e23633dd2088e6ff9b566d86d4618528212f;p=sage.d.git Add the divided_difference_coefficients() function. --- diff --git a/mjo/interpolation.py b/mjo/interpolation.py index 0cafc28..d5011ea 100644 --- a/mjo/interpolation.py +++ b/mjo/interpolation.py @@ -73,6 +73,26 @@ def lagrange_polynomial(x, xs, ys): return sigma + +def divided_difference_coefficients(xs): + """ + Assuming some function `f`, compute the coefficients of the + divided difference f[xs[0], ..., xs[n]]. + + TESTS: + + sage: divided_difference_coefficients([0]) + [1] + sage: divided_difference_coefficients([0, pi]) + [-1/pi, 1/pi] + sage: divided_difference_coefficients([0, pi, 2*pi]) + [1/2/pi^2, -1/pi^2, 1/2/pi^2] + + """ + coeffs = [ product([ (QQ(1) / (xj - xi)) for xi in xs if xi != xj ]) + for xj in xs ] + return coeffs + def divided_difference(f, xs): """ Return the Newton divided difference of `f` at the points