Created
July 25, 2013 22:51
-
-
Save jamesthompson/6084479 to your computer and use it in GitHub Desktop.
Bonnet's Recursion Formula using Spire for Polynomials...
Legendre Polynomials
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def legendres(i: Int) : List[Polynomial[Rational]] = { | |
val one = Polynomial(0 -> r"1/1") | |
val x = Polynomial(1 -> r"1/1") | |
lazy val leg : Stream[Polynomial[Rational]] = { | |
def loop(pnm1: Polynomial[Rational], pn: Polynomial[Rational], n: Int = 1) : Stream[Polynomial[Rational]] = { | |
pn #:: loop(pn, Polynomial(0 -> Numeric[Rational].fromInt(n + 1).reciprocal) * ( | |
(Polynomial(1 -> Numeric[Rational].fromInt(2 * n + 1)) * pn) + | |
(Polynomial(0 -> Numeric[Rational].fromInt(n).unary_-) * pnm1)), n + 1) | |
} | |
one #:: loop(one, x) | |
} | |
leg.take(i).toList | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment