From 03f0629ed5ea048ba00751d72e8508868b48fb66 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 4 Nov 2012 16:12:17 -0500 Subject: [PATCH] Add the lagrange_psi function. --- mjo/interpolation.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/mjo/interpolation.py b/mjo/interpolation.py index 70c35c1..8c3936e 100644 --- a/mjo/interpolation.py +++ b/mjo/interpolation.py @@ -93,6 +93,7 @@ def divided_difference_coefficients(xs): for xj in xs ] return coeffs + def divided_difference(xs, ys): """ Return the Newton divided difference of the points (xs[k], @@ -269,3 +270,25 @@ def hermite_interpolant(x, xs, ys, y_primes): for k in range(0, len(xs)) ]) return (s1 + s2) + + +def lagrange_psi(x, xs): + """ + The function, + + Psi(x) = (x - xs[0])*(x - xs[1])* ... *(x - xs[-1]) + + used in Lagrange and Hermite interpolation. + + INPUT: + + - ``x`` -- The independent variable of the resulting expression. + + - ``xs`` -- A list of points. + + OUTPUT: + + A symbolic expression in one variable, `x`. + """ + + return product([ (x - xj) for xj in xs ]) -- 2.43.2