A symbolic expression of one variable.
+ SETUP::
+
+ sage: from mjo.interpolation import lagrange_coefficient
+
TESTS::
sage: xs = [ -pi/2, -pi/6, 0, pi/6, pi/2 ]
sage: lagrange_coefficient(0, x, xs)
- 1/8*(pi - 6*x)*(pi - 2*x)*(pi + 6*x)*x/pi^4
+ 1/8*(pi + 6*x)*(pi - 2*x)*(pi - 6*x)*x/pi^4
"""
numerator = lagrange_psi(x, xs)/(x - xs[k])
def lagrange_polynomial(x, xs, ys):
"""
- Return the Lagrange form of the interpolation polynomial in `x` of
+ Return the Lagrange form of the interpolating polynomial in `x`
at the points (xs[k], ys[k]).
INPUT:
A symbolic expression (polynomial) interpolating each (xs[k], ys[k]).
+ SETUP::
+
+ sage: from mjo.interpolation import lagrange_polynomial
+
TESTS::
sage: xs = [ -pi/2, -pi/6, 0, pi/6, pi/2 ]
A polynomial in ``x`` which interpolates ``f`` at ``xs``.
+ SETUP::
+
+ sage: from mjo.interpolation import lagrange_interpolate
+
EXAMPLES:
We're exact on polynomials of degree `n` if we use `n+1` points::
Assuming some function `f`, compute the coefficients of the
divided difference f[xs[0], ..., xs[n]].
- TESTS:
+ SETUP::
+
+ sage: from mjo.interpolation import divided_difference_coefficients
+
+ TESTS::
sage: divided_difference_coefficients([0])
[1]
The (possibly symbolic) divided difference function.
+ SETUP::
+
+ sage: from mjo.interpolation import divided_difference
+
TESTS::
sage: xs = [0]
We try something entirely symbolic::
- sage: f = function('f', x)
+ sage: f = function('f')(x)
sage: divided_difference([x], [f(x=x)])
f(x)
sage: x1,x2 = SR.var('x1,x2')
A symbolic expression.
- TESTS:
+ SETUP::
+
+ sage: from mjo.interpolation import lagrange_polynomial, newton_polynomial
+
+ TESTS::
sage: xs = [ -pi/2, -pi/6, 0, pi/6, pi/2 ]
sage: ys = map(sin, xs)
A symbolic expression.
- TESTS:
+ SETUP::
+
+ sage: from mjo.interpolation import hermite_interpolant
+
+ TESTS::
sage: xs = [ 0, pi/6, pi/2 ]
sage: ys = map(sin, xs)