The product of all xs[j] with j != k.
"""
- return product([xs[k] - xs[j] for j in xrange(len(xs)) if j != k])
+ return product( xs[k] - xs[j] for j in xrange(len(xs)) if j != k )
def lagrange_coefficient(k, x, xs):
"""
ls = [ lagrange_coefficient(k, x, xs) for k in xrange(len(xs)) ]
- sigma = sum([ ys[k] * ls[k] for k in xrange(len(xs)) ])
- return sigma
+ return sum( ys[k] * ls[k] for k in xrange(len(xs)) )
[1/2/pi^2, -1/pi^2, 1/2/pi^2]
"""
- coeffs = [ QQ(1)/lagrange_denominator(k, xs) for k in xrange(len(xs)) ]
- return coeffs
+ return [ ~lagrange_denominator(k, xs) for k in xrange(len(xs)) ]
def divided_difference(xs, ys):
True
"""
- degree = len(xs) - 1
-
- N = SR(0)
-
- for k in xrange(degree+1):
- term = divided_difference(xs[:k+1], ys[:k+1])
- term *= lagrange_psi(x, xs[:k])
- N += term
-
- return N
+ return sum( divided_difference(xs[:k+1], ys[:k+1])*lagrange_psi(x, xs[:k])
+ for k in xrange(len(xs)) )
def hermite_coefficient(k, x, xs):
True
"""
- s1 = sum([ ys[k] * hermite_coefficient(k, x, xs)
- for k in xrange(len(xs)) ])
+ s1 = sum( ys[k] * hermite_coefficient(k, x, xs)
+ for k in xrange(len(xs)) )
- s2 = sum([ y_primes[k] * hermite_deriv_coefficient(k, x, xs)
- for k in xrange(len(xs)) ])
+ s2 = sum( y_primes[k] * hermite_deriv_coefficient(k, x, xs)
+ for k in xrange(len(xs)) )
return (s1 + s2)
"""
- return product([ (x - xj) for xj in xs ])
+ return product( (x - xj) for xj in xs )