Skip to content

Commit

Permalink
Add normalisation to Legendre basis.
Browse files Browse the repository at this point in the history
  • Loading branch information
michakraus committed Dec 16, 2020
1 parent a227cf0 commit 6da33a6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
9 changes: 5 additions & 4 deletions src/legendre.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
24 changes: 12 additions & 12 deletions test/legendre_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

2 comments on commit 6da33a6

@michakraus
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/26508

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.0 -m "<description of version>" 6da33a68388af0ce6f112cf3f7136a180102194f
git push origin v0.2.0

Please sign in to comment.