Skip to content
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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

dianetambey
Copy link

finite differences: boundary conditions and formula fix
ex 2: * missing in formula
ex 4: put in square box
sol 1: formula fix

Copy link
Member

@mfherbst mfherbst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, some nits.

@@ -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'}
Copy link
Member

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)

Copy link
Author

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.

@@ -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"
Copy link
Member

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right thanks !

Copy link
Member

@mfherbst mfherbst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some first notes.

@@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# *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 `$`).

@@ -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
Copy link
Member

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.

# !!! 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why \bullet ?

Copy link
Author

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 ?

Comment on lines 205 to 213
# 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:
Copy link
Member

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

Suggested change
# 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:

Comment on lines 218 to 220
# ```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).
# ```
Copy link
Member

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.

@mfherbst mfherbst changed the title fix in finite differences, ex 2, ex 4, sol 1 Solutions to discretisation exercises Aug 14, 2024
using LinearAlgebra

function build_plane_waves_matrix_cos(N::Integer)
# Plane wave approximation to -½Δ
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here as well: ## using ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants