-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solutions to discretisation exercises #993
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, some nits.
docs/src/guide/discretisation.jl
Outdated
@@ -63,7 +63,7 @@ end; | |||
# !!! tip "Exercise 2" | |||
# Show that | |||
# ```math | |||
# \langle e_G, e_{G'}\rangle = ∫_0^{2π} e_G(x) e_{G'}(x) d x = δ_{G, G'} | |||
# \langle e_G, e_{G'}\rangle = ∫_0^{2π} e_G(x)\ast e_{G'}(x) d x = δ_{G, G'} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better: e_G^\ast(x)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I will fix that.
docs/src/guide/discretisation.jl
Outdated
@@ -118,7 +118,8 @@ plot(real(ψ); label="") | |||
|
|||
# Again this should match with the result above. | |||
# | |||
# **Exercise 4:** Look at the Fourier coefficients of $\psi$ ($\psi$_fourier) | |||
# !!! "Exercise 4" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the syntax here and the next line is not correct (some keyword missing after !!! & indention in next lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right thanks !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some first notes.
docs/src/guide/discretisation.jl
Outdated
@@ -147,7 +148,7 @@ Array(H) | |||
# !!! tip "Exercise 6" | |||
# Increase the size of the problem, and compare the time spent | |||
# by DFTK's internal diagonalization algorithms to a full diagonalization of `Array(H)`. | |||
# *Hint:* The `@time` macro is handy for this task. | |||
# *Hint:* The `@benchmark` macro is handy for this task. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# *Hint:* The `@benchmark` macro is handy for this task. | |
# *Hint:* The `@benchmark` macro (from the [BenchmarkTools](https://github.com/JuliaCI/BenchmarkTools.jl) package) is handy for this task. Note that there are some subtleties with global variables (see the BenchmarkTools docs for details). E.g. to use it to benchmark a function like `eigen(H)` run it as | |
# ``` | |
# using BenchmarkTools | |
# @benchmark eigen($H) | |
# ``` | |
# (note the `$`). |
docs/src/guide/discretisation.jl
Outdated
@@ -198,22 +199,121 @@ Nrange = 10:10:100 | |||
plot(Nrange, abs.(fconv.(Nrange) .- fconv(200)); yaxis=:log, legend=false) | |||
|
|||
# ### Exercise 2 | |||
# !!! note "TODO" | |||
# This solution has not yet been written. Any help with a PR is appreciated. | |||
# ```math |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to indent this and other math blocks.
docs/src/guide/discretisation.jl
Outdated
# !!! note "TODO" | ||
# This solution has not yet been written. Any help with a PR is appreciated. | ||
# ```math | ||
# \bullet \langle e_G, e_{G'}\rangle = ∫_0^{2π} e_G^\ast(x) e_{G'}(x) d x = 1/2π ∫_0^{2π} e^i(G'-G)x d x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why \bullet
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought I would put a bullet for each part of the equation, should I remove it ?
docs/src/guide/discretisation.jl
Outdated
# if G≠G', since the function is periodic over $[0, 2\pi]$: | ||
# ```math | ||
# \langle e_G, e_{G'}\rangle = \frac 1 {i2π(G'-G)} ∫_0^{2π} (e^{ix})^{G'-G} d x = 0 | ||
# ``` | ||
# if G=G': | ||
# ```math | ||
# \langle e_G, e_{G'}\rangle = \frac 1 {2π} ∫_0^{2π} d x = 1 | ||
# ``` | ||
# Therefore: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which function ? I think that's a bit wordy
# if G≠G', since the function is periodic over $[0, 2\pi]$: | |
# ```math | |
# \langle e_G, e_{G'}\rangle = \frac 1 {i2π(G'-G)} ∫_0^{2π} (e^{ix})^{G'-G} d x = 0 | |
# ``` | |
# if G=G': | |
# ```math | |
# \langle e_G, e_{G'}\rangle = \frac 1 {2π} ∫_0^{2π} d x = 1 | |
# ``` | |
# Therefore: | |
# Since `e^{iy}` is a periodic function with period $2\pi$, $\int_0^{2\pi} e^{i m y} dy = \delta_{0,m}$. Therefore: |
docs/src/guide/discretisation.jl
Outdated
# ```math | ||
# \langle e_G, H e_{G'}\rangle = \frac 1 2 ∫_0^{2π} e_G^\ast(x) H e_{G'}(x) d x \left(|G|^2 \delta_{G,G'} + \delta_{G, G'+1} + \delta_{G, G'-1}\right). | ||
# ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the final result, right ? I would not repeat that here. People can read it in the question.
using LinearAlgebra | ||
|
||
function build_plane_waves_matrix_cos(N::Integer) | ||
# Plane wave approximation to -½Δ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you put in-line comments in code segments, they need to start with ## ... Ask me later why if you are curious
function build_plane_waves_matrix_cos(N::Integer) | ||
# Plane wave approximation to -½Δ | ||
G = [float((-N + i)^2) for i in 0:2N] | ||
#using results from exercice 2 for the case of cos potential, the following matrix is built for the Hamiltonian |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here as well: ## using ...
finite differences: boundary conditions and formula fix
ex 2: * missing in formula
ex 4: put in square box
sol 1: formula fix