在提问之前请确定你已经努力阅读了文档,并且尝试自己在互联网上搜索。
请尽可能提供你的demo代码或者GitHub的gist地址。
# code
```u = ones(npw)
u = u/norm(u)
b = u
λ1 = 0.0
erro = 1.0
H, G, I = hamiltonian(atoms, model, v1, v2)
# begin iteration
while erro > 0.001
H1 = zeros(npw,npw)
v = zeros(4*mmax+1,4*mmax+1)
for G1=1:npw,G2=1:npw
v[I[G1,1]-I[G2,1]+2*mmax+1,I[G1,2]-I[G2,2]+2*mmax+1] += b[G1]*b[G2]
end
# update Hamitonion
for G1=1:npw,G2=1:npw
H1[G1,G2] = H[G1,G2] + v[I[G1,1]-I[G2,1]+2*mmax+1,I[G1,2]-I[G2,2]+2*mmax+1]
end
D, Ψ =(eigen(H1)...,)
λ = sort(D)[1:npw]
erro = abs(λ[1]-λ1)
println("the first eigenvalue is", λ[1])
λ1 = λ[1]
index = sortperm(D)[1]
b = u
u = Ψ[:,index]
end