Skip to content

Commit

Permalink
update DeltaPotential
Browse files Browse the repository at this point in the history
  • Loading branch information
ohno committed Feb 8, 2024
1 parent 7dcc4cf commit 7f62365
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 30 deletions.
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ makedocs(;
"Harmonic Oscillator" => "HarmonicOscillator.md" ,
"Morse Potential" => "MorsePotential.md" ,
"Hydrogen Atom" => "HydrogenAtom.md" ,
"Delta Potential" => "DeltaPotential.md" ,
],
)

Expand Down
91 changes: 88 additions & 3 deletions docs/src/DeltaPotential.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
CurrentModule = Antique
```


# Delta Potential

The Delta potential is one the simplest models for quantum mechanical system in 1D.
Expand All @@ -19,7 +18,7 @@ It always has one bound state and its wave function has a cusp at the origin.

#### Hamiltonian
```math
\hat{H} = \frac{\hbar^2}{2m} \frac{\mathrm{d}^2}{\mathrm{d}x ^2} + V(x)
\hat{H} = - \frac{\hbar^2}{2m} \frac{\mathrm{d}^2}{\mathrm{d}x ^2} + V(x)
```

#### Potential
Expand All @@ -40,11 +39,97 @@ It always has one bound state and its wave function has a cusp at the origin.
\psi(x) = \frac{\sqrt{m\alpha}}{\hbar} \mathrm{e}^{-m\alpha |x|/\hbar^2}
```

## Usage & Examples

[Install Antique.jl](@ref Install) for the first use and run `using Antique` before each use. The energy `E()`, wavefunction `ψ()`, potential `V()` and some other functions are suppoted. In this system, the model is generated by `DeltaPotential` and several parameters `α`, `m` and `` are set as optional arguments.

```julia
using Antique
DP = DeltaPotential=1.0, m=1.0, ℏ=1.0)
```




Parameters:

```julia
julia> DP.α
1.0

julia> DP.m
1.0

julia> DP.
1.0
```



Eigen values:

```julia
julia> E(DP)
-0.5
```



Wave functions:

```julia
DP = DeltaPotential=0.1, m=0.5, ℏ=0.1)
x = LinRange(-2,2,500);

using Plots
plot(x, x->ψ(DP,x), linewidth=3)
plot!(xlim=[-2,2], ylim=[0,2.5], legend=false)
plot!(xlabel="x", ylabel="ψ(x)", title="Delta Potential")
```

![](./assets/fig//DeltaPotential_4_1.png)



## Testing

Unit testing and Integration testing were done using numerical integration ([QuadGK.jl](https://juliamath.github.io/QuadGK.jl/stable/)). The test script is [here](https://github.com/ohno/Antique.jl/blob/main/test/DeltaPotential.jl).

Error: UndefVarError: `Antique` not defined
#### Normalization of $\psi(x)$

```math
\int_{-\infty}^{\infty} \psi^\ast(x) \psi(x) ~\mathrm{d}x = 1
```

```
α | m | ℏ | analytical | numerical
--- | --- | --- | ----------------- | -----------------
0.1 | 0.1 | 0.1 | 1.000000000000 | 1.000000000000 ✔
0.1 | 0.1 | 1.0 | 1.000000000000 | 1.000000000000 ✔
0.1 | 0.1 | 7.0 | 1.000000000000 | 1.000004676239 ✔
0.1 | 1.0 | 0.1 | 1.000000000000 | 1.000000000000 ✔
0.1 | 1.0 | 1.0 | 1.000000000000 | 1.000000000000 ✔
0.1 | 1.0 | 7.0 | 1.000000000000 | 0.999999999999 ✔
0.1 | 7.0 | 0.1 | 1.000000000000 | 1.000000000000 ✔
0.1 | 7.0 | 1.0 | 1.000000000000 | 1.000000000000 ✔
0.1 | 7.0 | 7.0 | 1.000000000000 | 1.000000000000 ✔
1.0 | 0.1 | 0.1 | 1.000000000000 | 1.000000000000 ✔
1.0 | 0.1 | 1.0 | 1.000000000000 | 1.000000000000 ✔
1.0 | 0.1 | 7.0 | 1.000000000000 | 0.999999999999 ✔
1.0 | 1.0 | 0.1 | 1.000000000000 | 1.000000000000 ✔
1.0 | 1.0 | 1.0 | 1.000000000000 | 1.000000000000 ✔
1.0 | 1.0 | 7.0 | 1.000000000000 | 1.000000000000 ✔
1.0 | 7.0 | 0.1 | 1.000000000000 | 1.000000000000 ✔
1.0 | 7.0 | 1.0 | 1.000000000000 | 1.000000000000 ✔
1.0 | 7.0 | 7.0 | 1.000000000000 | 1.000000000000 ✔
7.0 | 0.1 | 0.1 | 1.000000000000 | 1.000000000000 ✔
7.0 | 0.1 | 1.0 | 1.000000000000 | 1.000000000000 ✔
7.0 | 0.1 | 7.0 | 1.000000000000 | 1.000000000000 ✔
7.0 | 1.0 | 0.1 | 1.000000000000 | 1.000000000000 ✔
7.0 | 1.0 | 1.0 | 1.000000000000 | 1.000000000000 ✔
7.0 | 1.0 | 7.0 | 1.000000000000 | 1.000000000000 ✔
7.0 | 7.0 | 0.1 | 1.000000000000 | 1.000000000000 ✔
7.0 | 7.0 | 1.0 | 1.000000000000 | 1.000000000000 ✔
7.0 | 7.0 | 7.0 | 1.000000000000 | 1.000000000000 ✔
```
2 changes: 1 addition & 1 deletion docs/src/InfinitePotentialWell.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The infinite potential well (particle in a box) is the simplest model for quantu

#### Hamiltonian
```math
\hat{H} = \frac{\hbar^2}{2m} \frac{\mathrm{d}^2}{\mathrm{d}x ^2} + V(x)
\hat{H} = - \frac{\hbar^2}{2m} \frac{\mathrm{d}^2}{\mathrm{d}x ^2} + V(x)
```

#### Potential
Expand Down
Binary file added docs/src/assets/fig/DeltaPotential_4_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 36 additions & 2 deletions docs/src/jmd/DeltaPotential.jmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
CurrentModule = Antique
```


# Delta Potential

The Delta potential is one the simplest models for quantum mechanical system in 1D.
Expand All @@ -19,7 +18,7 @@ It always has one bound state and its wave function has a cusp at the origin.

#### Hamiltonian
```math
\hat{H} = \frac{\hbar^2}{2m} \frac{\mathrm{d}^2}{\mathrm{d}x ^2} + V(x)
\hat{H} = - \frac{\hbar^2}{2m} \frac{\mathrm{d}^2}{\mathrm{d}x ^2} + V(x)
```

#### Potential
Expand All @@ -40,6 +39,41 @@ It always has one bound state and its wave function has a cusp at the origin.
\psi(x) = \frac{\sqrt{m\alpha}}{\hbar} \mathrm{e}^{-m\alpha |x|/\hbar^2}
```

## Usage & Examples

[Install Antique.jl](@ref Install) for the first use and run `using Antique` before each use. The energy `E()`, wavefunction `ψ()`, potential `V()` and some other functions are suppoted. In this system, the model is generated by `DeltaPotential` and several parameters `α`, `m` and `ℏ` are set as optional arguments.

```julia; cache = :all; results = "hidden"
using Antique
DP = DeltaPotential(α=1.0, m=1.0, ℏ=1.0)
```

Parameters:

```julia; term = true
DP.α
DP.m
DP.ℏ
```

Eigen values:

```julia; term = true
E(DP)
```

Wave functions:

```julia
DP = DeltaPotential(α=0.1, m=0.5, ℏ=0.1)
x = LinRange(-2,2,500);

using Plots
plot(x, x->ψ(DP,x), linewidth=3)
plot!(xlim=[-2,2], ylim=[0,2.5], legend=false)
plot!(xlabel="x", ylabel="ψ(x)", title="Delta Potential")
```

## Testing

Unit testing and Integration testing were done using numerical integration ([QuadGK.jl](https://juliamath.github.io/QuadGK.jl/stable/)). The test script is [here](https://github.com/ohno/Antique.jl/blob/main/test/DeltaPotential.jl).
Expand Down
2 changes: 1 addition & 1 deletion docs/src/jmd/InfinitePotentialWell.jmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The infinite potential well (particle in a box) is the simplest model for quantu

#### Hamiltonian
```math
\hat{H} = \frac{\hbar^2}{2m} \frac{\mathrm{d}^2}{\mathrm{d}x ^2} + V(x)
\hat{H} = - \frac{\hbar^2}{2m} \frac{\mathrm{d}^2}{\mathrm{d}x ^2} + V(x)
```

#### Potential
Expand Down
31 changes: 14 additions & 17 deletions test/DeltaPotential.jl
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
DP = DeltaPotential=1.0,m=1.0, ℏ=1.0)
DP = DeltaPotential=1.0, m=1.0, ℏ=1.0)

# <ψᵢ|ψⱼ> = ∫ψ*ψdx = δᵢⱼ

println(raw"""
#### Normalization & Orthogonality of $\psi(x)$
#### Normalization of $\psi(x)$
```math
\int_{-Inf}^{Inf} \psi^\ast(x) \psi(x) ~\mathrm{d}x = 1
\int_{-\infty}^{\infty} \psi^\ast(x) \psi(x) ~\mathrm{d}x = 1
```
```""")

@testset "<ψ|ψ> = ∫ψ*ψdx = 1" begin
println(" analytical | numerical ")
println(" ----------------- | ----------------- ")
# for L in [0.1, 0.5, 1.0, 7.0]
# for m in [0.1, 0.5, 1.0, 7.0]
# for ℏ in [0.1, 0.5, 1.0, 7.0]
# for i in 1:10
# for j in 1:10
println(" α | m | ℏ | analytical | numerical ")
println("--- | --- | --- | ----------------- | ----------------- ")
for α in [0.1, 1.0, 7.0]
for m in [0.1, 1.0, 7.0]
forin [0.1, 1.0, 7.0]
DP = DeltaPotential=α, m=m, ℏ=ℏ)
analytical = 1
numerical = quadgk(x -> conj(ψ(DP, x)) * ψ(DP, x), -Inf, Inf, maxevals=10^3)[1]
numerical = quadgk(x -> conj(ψ(DP, x)) * ψ(DP, x), -Inf, Inf, maxevals=10^3, order=10)[1]
acceptance = iszero(analytical) ? isapprox(analytical, numerical, atol=1e-5) : isapprox(analytical, numerical, rtol=1e-5)
@test acceptance
@printf("%17.12f | %17.12f %s\n", analytical, numerical, acceptance ? "" : "")
# end
# end
# end
# end
# end
@printf("%.1f | %.1f | %.1f | %17.12f | %17.12f %s\n", α, m, ℏ, analytical, numerical, acceptance ? "" : "")
end
end
end
end

println("""```
Expand Down
36 changes: 31 additions & 5 deletions test/result/DeltaPotential.log
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
#### Normalization & Orthogonality of $\psi(x)$
#### Normalization of $\psi(x)$

```math
\int_{-Inf}^{Inf} \psi^\ast(x) \psi(x) ~\mathrm{d}x = 1
\int_{-\infty}^{\infty} \psi^\ast(x) \psi(x) ~\mathrm{d}x = 1
```

```
analytical | numerical
----------------- | -----------------
1.000000000000 | 1.000000000000 ✔
α | m | ℏ | analytical | numerical
--- | --- | --- | ----------------- | -----------------
0.1 | 0.1 | 0.1 | 1.000000000000 | 1.000000000000 ✔
0.1 | 0.1 | 1.0 | 1.000000000000 | 1.000000000000 ✔
0.1 | 0.1 | 7.0 | 1.000000000000 | 1.000004676239 ✔
0.1 | 1.0 | 0.1 | 1.000000000000 | 1.000000000000 ✔
0.1 | 1.0 | 1.0 | 1.000000000000 | 1.000000000000 ✔
0.1 | 1.0 | 7.0 | 1.000000000000 | 0.999999999999 ✔
0.1 | 7.0 | 0.1 | 1.000000000000 | 1.000000000000 ✔
0.1 | 7.0 | 1.0 | 1.000000000000 | 1.000000000000 ✔
0.1 | 7.0 | 7.0 | 1.000000000000 | 1.000000000000 ✔
1.0 | 0.1 | 0.1 | 1.000000000000 | 1.000000000000 ✔
1.0 | 0.1 | 1.0 | 1.000000000000 | 1.000000000000 ✔
1.0 | 0.1 | 7.0 | 1.000000000000 | 0.999999999999 ✔
1.0 | 1.0 | 0.1 | 1.000000000000 | 1.000000000000 ✔
1.0 | 1.0 | 1.0 | 1.000000000000 | 1.000000000000 ✔
1.0 | 1.0 | 7.0 | 1.000000000000 | 1.000000000000 ✔
1.0 | 7.0 | 0.1 | 1.000000000000 | 1.000000000000 ✔
1.0 | 7.0 | 1.0 | 1.000000000000 | 1.000000000000 ✔
1.0 | 7.0 | 7.0 | 1.000000000000 | 1.000000000000 ✔
7.0 | 0.1 | 0.1 | 1.000000000000 | 1.000000000000 ✔
7.0 | 0.1 | 1.0 | 1.000000000000 | 1.000000000000 ✔
7.0 | 0.1 | 7.0 | 1.000000000000 | 1.000000000000 ✔
7.0 | 1.0 | 0.1 | 1.000000000000 | 1.000000000000 ✔
7.0 | 1.0 | 1.0 | 1.000000000000 | 1.000000000000 ✔
7.0 | 1.0 | 7.0 | 1.000000000000 | 1.000000000000 ✔
7.0 | 7.0 | 0.1 | 1.000000000000 | 1.000000000000 ✔
7.0 | 7.0 | 1.0 | 1.000000000000 | 1.000000000000 ✔
7.0 | 7.0 | 7.0 | 1.000000000000 | 1.000000000000 ✔
```


2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using LaTeXStrings
using SpecialFunctions

@testset "Antique.jl" begin
for model in Antique.models
for model in [:DeltaPotential] # Antique.models
result = @capture_out begin
include("./$(model).jl")
end
Expand Down

0 comments on commit 7f62365

Please sign in to comment.