X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=mjo%2Forthogonal_polynomials.py;h=7544f65c048c72662ff72c40bbcb1197a98382a7;hb=852c32e6db3d27310489abd9e23787a1b7d068ad;hp=fd5fd75317b9f07b9108dd41ebd74d6606f9fd12;hpb=5f0f517a80ae4f3e12bf4d3a84ea3d182cb96e70;p=sage.d.git diff --git a/mjo/orthogonal_polynomials.py b/mjo/orthogonal_polynomials.py index fd5fd75..7544f65 100644 --- a/mjo/orthogonal_polynomials.py +++ b/mjo/orthogonal_polynomials.py @@ -1,7 +1,7 @@ from sage.all import * def legendre_p(n, x, a = -1, b = 1): - """ + r""" Returns the ``n``th Legendre polynomial of the first kind over the interval [a, b] with respect to ``x``. @@ -72,15 +72,12 @@ def legendre_p(n, x, a = -1, b = 1): sage: a = -pi sage: b = pi sage: def inner_product(v1, v2): - ... return integrate(v1*v2, x, a, b) - ... + ....: return integrate(v1*v2, x, a, b) sage: def norm(v): - ... return sqrt(inner_product(v,v)) - ... + ....: return sqrt(inner_product(v,v)) sage: def project(basis, v): - ... return sum([ inner_product(v, b)*b/norm(b)**2 - ... for b in basis]) - ... + ....: return sum( inner_product(v, b)*b/norm(b)**2 + ....: for b in basis) sage: f = sin(x) sage: legendre_basis = [ legendre_p(k, x, a, b) for k in xrange(4) ] sage: proj = project(legendre_basis, f) @@ -92,7 +89,7 @@ def legendre_p(n, x, a = -1, b = 1): We should agree with Maxima for all `n`:: sage: eq = lambda k: bool(legendre_p(k,x) == legendre_P(k,x)) - sage: all([eq(k) for k in xrange(20) ]) # long time + sage: all( eq(k) for k in xrange(20) ) # long time True We can evaluate the result of the zeroth polynomial:: @@ -196,6 +193,6 @@ def legendre_p(n, x, a = -1, b = 1): # From Abramowitz & Stegun, (22.3.2) with alpha = beta = 0. # Also massaged to support finite field elements. - P = sum([ c(m)*g(m) for m in xrange(n+1) ])/(2**n) + P = sum( c(m)*g(m) for m in xrange(n+1) )/(2**n) return P