Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/src/Rayleigh-Ritz.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ println(" Reference: ", -0.495010)

The results agree with those in Table 1 of the Supporting Information. The small differences between the calculated and reference values arise from rounding in the published parameters.

## Acknowledgments

We thank the participants of the [JuliaHEP Workshop 2025](https://indico.cern.ch/e/juliahep2025) for feedback on matrix assembly.

## API reference

### Solver
Expand Down
11 changes: 6 additions & 5 deletions src/Rayleigh-Ritz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,12 @@ end

function matrix(hamiltonian::Hamiltonian, basisset::BasisSet)
nₘₐₓ = length(basisset.basis)
# H = [element(hamiltonian, basisset.basis[i], basisset.basis[j]) for i=1:nₘₐₓ, j=1:nₘₐₓ]
H = Array{Float64}(undef, nₘₐₓ, nₘₐₓ)
for j in 1:nₘₐₓ
for i in 1:j
H[i,j] = element(hamiltonian, basisset.basis[i], basisset.basis[j])
H = zeros(Float64, nₘₐₓ, nₘₐₓ)
for operator in hamiltonian.terms
for j in 1:nₘₐₓ
for i in 1:j
H[i,j] += element(operator, basisset.basis[i], basisset.basis[j])
end
end
end
return LinearAlgebra.Symmetric(H)
Expand Down
2 changes: 2 additions & 0 deletions test/Rayleigh-Ritz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
SimpleGaussianBasis(0.1219492),
)
res = solve(H, BS)

@test TwoBody.matrix(H, BS) ≈ sum(TwoBody.matrix(term, BS) for term in H.terms)

println("4π×∫|ψ(r)|²r²dr = 1")
println(" i\tnumerical \tanalytical")
Expand Down
Loading