Post Reply 
(33S) Legendre Polynomials
05-20-2022, 05:51 PM (This post was last modified: 05-20-2022 06:39 PM by Albert Chan.)
Post: #8
RE: (33S) Legendre Polynomials
From https://solitaryroad.com/c679.html, P(n,x) and Q(n,x) are based on same recurrence relation formula.
Note: this version extended range to all non-negative integers n. (i.e. n=0 included)

Code:
function legendre_hlp(n,x,p0,k0)
    local p1,k1 = x*p0-k0
    for k=2,n do k0=k-1; k1=k+k0; p0, p1 = p1, (k1*p1*x-k0*p0)/k end
    return (n==0 and p0) or p1
end
    
function P(n,x) return legendre_hlp(n,x,1,0) end
function Q(n,x) return legendre_hlp(n,x,atanh(x),1) end

lua> P(4,4)
1060.375
lua> P(9,0.5)
-0.2678985595703125

lua> Q(0, 0.5)
0.5493061443340549
lua> Q(10, 0.4)
0.37399122844670774

Numbers matched L4 (Legendre Polynomials) numbers (previous post)

(05-20-2022 04:10 PM)Thomas Klemm Wrote:  The program also implements the Legendre functions of the second kind (Qn)

Use a negative value for \( x \) in this case ...

What happens if x = 0 ? Which legendre kind get returned ?
I would assume first kind (x = +0), since signed zero may not be supported.

This may be confusing, since P(n,0) ≠ Q(n,0)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (33S) Legendre Polynomials - Albert Chan - 05-20-2022 05:51 PM



User(s) browsing this thread: 3 Guest(s)