Skip to content

Instantly share code, notes, and snippets.

@jamesthompson
Created June 10, 2012 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesthompson/2906929 to your computer and use it in GitHub Desktop.
Save jamesthompson/2906929 to your computer and use it in GitHub Desktop.
Legendre Polynomials
def leg(mode:Int, angle:Double) : IndexedSeq[Double] = {
val cosAngle = math.cos(angle)
lazy val stream: Stream[Double] = {
def loop(last:Double, curr:Double, k:Double = 0.0) : Stream[Double] = curr #:: loop(curr, ((2 * k + 1) * cosAngle * curr - k * last) / (k + 1), k + 1)
loop(0.0, 1.0)
}
stream.take(mode + 1).toIndexedSeq
}
@jamesthompson
Copy link
Author

Stream Legendre Polynomials

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment