From 0594e23633dd2088e6ff9b566d86d4618528212f Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Fri, 26 Oct 2012 14:13:03 -0400 Subject: [PATCH] Add the divided_difference_coefficients() function. --- mjo/interpolation.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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 -- 2.43.2