diff --git a/src/legendre.jl b/src/legendre.jl index 3f631b9..d9301b1 100644 --- a/src/legendre.jl +++ b/src/legendre.jl @@ -23,7 +23,7 @@ struct Legendre{T, LT} <: Basis{T} function Legendre{T}(n::Integer) where {T} p = n-1 - b = OffsetArray([y -> _legendre(i, 2y-1) for i in 0:p], 0:p) + b = OffsetArray([y -> _legendre(i, 2y-1) * sqrt(T(2i+1)) for i in 0:p], 0:p) new{T, typeof(b)}(b, n) end @@ -32,9 +32,10 @@ end Legendre(::Type{T}, n::Integer) where {T} = Legendre{T}(n) Legendre(n::Integer) = Legendre(Float64, n) -function _eval(l::Legendre{LT}, x::DT, j::Int) where {LT,DT} - @assert j ≥ 0 && j < l.n - _legendre(j, 2x-1) +function _eval(L::Legendre{LT}, x::DT, j::Int) where {LT,DT} + local T = promote_type(LT, DT) + @assert j ≥ 0 && j < L.n + _legendre(j, 2x-1) * sqrt(T(2j+1)) end (L::Legendre)(x::Number, j::Integer) = L.b[j](x) diff --git a/test/legendre_tests.jl b/test/legendre_tests.jl index 269dd8b..59ac6b3 100644 --- a/test/legendre_tests.jl +++ b/test/legendre_tests.jl @@ -54,26 +54,26 @@ import ContinuumArrays: apply, MulQuasiMatrix @test l(0.5, 0) == 1.0 @test l(1.0, 0) == 1.0 - @test l(0.0, 1) == -1.0 + @test l(0.0, 1) == -sqrt(3) @test l(0.5, 1) == 0.0 - @test l(1.0, 1) == +1.0 + @test l(1.0, 1) == +sqrt(3) @test l[0.0, 0] == 1.0 @test l[0.5, 0] == 1.0 @test l[1.0, 0] == 1.0 - @test l[0.0, 1] == -1.0 + @test l[0.0, 1] == -sqrt(3) @test l[0.5, 1] == 0.0 - @test l[1.0, 1] == +1.0 + @test l[1.0, 1] == +sqrt(3) @test l[0, 0] == 1.0 @test l[1, 0] == 1.0 @test l[2, 0] == 1.0 - @test l[0, 1] == -1.0 - @test l[1, 1] == +1.0 - @test l[2, 1] == +3.0 + @test l[0, 1] == -sqrt(3) + @test l[1, 1] == +sqrt(3) + @test l[2, 1] == +sqrt(27) @test (d*l)[0.0, 0] == 0.0 @@ -102,13 +102,13 @@ import ContinuumArrays: apply, MulQuasiMatrix @test l[0.5, 0] == 1.0 @test l[1.0, 0] == 1.0 - @test l(0.0, 1) == -1.0 + @test l(0.0, 1) == -sqrt(3) @test l(0.5, 1) == 0.0 - @test l(1.0, 1) == +1.0 + @test l(1.0, 1) == +sqrt(3) - @test l[0.0, 2] == +1.0 - @test l[0.5, 2] == -0.5 - @test l[1.0, 2] == +1.0 + @test l[0.0, 2] == +1.0 * sqrt(5) + @test l[0.5, 2] == -0.5 * sqrt(5) + @test l[1.0, 2] == +1.0 * sqrt(5) @test (d*l)[0.0, 0] == 0.0 @test (d*l)[0.5, 0] == 0.0