Skip to content

Commit 6691f83

Browse files
authored
Don't normalize eigenfunctions in examples (#882)
* don't re-normalize eigenfunctions in examples * use real part of eigenvalues
1 parent ced61b3 commit 6691f83

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
2222

2323
[compat]
2424
AbstractFFTs = "1.0"
25-
ApproxFunBase = "0.8.20"
25+
ApproxFunBase = "0.8.24"
2626
ApproxFunBaseTest = "0.1"
2727
ApproxFunFourier = "0.3"
2828
ApproxFunOrthogonalPolynomials = "0.5, 0.6"

examples/Eigenvalue.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Plots
99
using LinearAlgebra: norm
1010
p = Plots.plot(V, legend=false, ylim=(-Inf, λ[22]))
1111
for k=1:20
12-
Plots.plot!(real(v[k]/norm(v[k]) + λ[k]))
12+
Plots.plot!(real(v[k]) + real(λ[k]))
1313
end
1414
p
1515

@@ -28,21 +28,21 @@ Plots.plot(λ, title = "Eigenvalues", legend=false)
2828
include("Eigenvalue_well_barrier.jl")
2929

3030
# We plot the first few eigenfunctions offset by their eigenvalues.
31-
# The eigenfunctions appear in odd-even pairs as expected.
31+
# The eigenfunctions appear in odd-even pairs by construction.
3232

3333
import Plots
3434
using LinearAlgebra: norm
3535
p1 = Plots.plot(Vfull, legend=false, ylim=(-Inf, λ[14]), title="Eigenfunctions",
3636
seriestype=:path, linestyle=:dash, linewidth=2)
3737
Plots.vline!([-Lx/2, Lx/2], color=:black)
3838
for k=1:12
39-
Plots.plot!(real(v[k]/norm(v[k]) + λ[k]))
39+
Plots.plot!(real(v[k]) + λ[k])
4040
end
4141

4242
# Zoom into the ground state:
4343
p2 = Plots.plot(Vfull, legend=false, ylim=(-Inf, λ[3]), title="Ground state",
4444
seriestype=:path, linestyle=:dash, linewidth=2)
4545
Plots.vline!([-Lx/2, Lx/2], color=:black)
46-
Plots.plot!(real(v[1]/norm(v[1]) + λ[1]), linewidth=2)
46+
Plots.plot!(real(v[1]) + λ[1], linewidth=2)
4747

4848
Plots.plot(p1, p2, layout = 2)

examples/Eigenvalue_well_barrier.jl

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@ Scomplement = Legendre(-Lx/2..0);
3535
# and those of even orders are even functions
3636
# Using this, for the odd solutions, we negate the even-order coefficients to construct the odd image in `-Lx/2..0`
3737
function oddimage(f, Scomplement)
38-
coeffs = [(-1)^isodd(m) * c for (m,c) in enumerate(coefficients(f))]
39-
Fun(Scomplement, coeffs)
40-
end;
38+
coeffs = [(-1)^isodd(m) * c for (m,c) in enumerate(coefficients(f))]
39+
Fun(Scomplement, coeffs)
40+
end
4141
voddimage = oddimage.(vodd, Scomplement);
4242

4343
# Construct the functions over the entire domain `-Lx/2..Lx/2` as piecewise sums over the two half domains `-Lx/2..0` and `0..Lx/2`
44-
voddfull = voddimage .+ vodd;
44+
# The eigenfunctions `vodd` are normalized on the half-domain, so we normalize the sum by dividing it by `√2`
45+
voddfull = (voddimage .+ vodd)./√2;
4546

4647
# Even solutions, with a Neumann condition at `0` representing the symmetry of the function
4748
B = [lneumann(S); rdirichlet(S)];
@@ -51,16 +52,16 @@ Seig = ApproxFun.SymmetricEigensystem(H, B);
5152

5253
# For the even solutions, we negate the odd-order coefficients to construct the even image in `-Lx/2..0`
5354
function evenimage(f, Scomplement)
54-
coeffs = [(-1)^iseven(m) * c for (m,c) in enumerate(coefficients(f))]
55-
Fun(Scomplement, coeffs)
56-
end;
55+
coeffs = [(-1)^iseven(m) * c for (m,c) in enumerate(coefficients(f))]
56+
Fun(Scomplement, coeffs)
57+
end
5758
vevenimage = evenimage.(veven, Scomplement);
58-
vevenfull = vevenimage .+ veven;
59+
vevenfull = (vevenimage .+ veven)./√2;
5960

6061
# We interlace the eigenvalues and eigenvectors to obtain the entire spectrum
6162
function interlace(a::AbstractVector, b::AbstractVector)
62-
vec(permutedims([a b]))
63-
end;
63+
vec(permutedims([a b]))
64+
end
6465
λ = interlace(λeven, λodd);
6566
v = interlace(vevenfull, voddfull);
6667

0 commit comments

Comments
 (0)