-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
1345 lines (525 loc) · 33.8 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html><html lang="en-us" >
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="generator" content="Wowchemy 5.4.0 for Hugo" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link rel="preload" as="style" href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;700&family=Roboto+Mono&family=Roboto:wght@400;700&display=swap">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;700&family=Roboto+Mono&family=Roboto:wght@400;700&display=swap" media="print" onload="this.media='all'">
<meta name="google-site-verification" content="Bhl7mMlFZKqx2U0A2Ob6-eSffTc38xtZyQSY-WyF4xA" />
<meta name="author" content="Orjan Ameye" />
<meta name="description" content="The eigenfunctions of the time independent Schrödinger equation are numerically computed by discretising with the finite difference method and using exact diagonalisation of sparse matrices." />
<link rel="alternate" hreflang="en-us" href="https://oameye.github.io/post/eigenfunctions/" />
<meta name="theme-color" content="#4caf50" />
<script src="/js/mathjax-config.js"></script>
<link rel="stylesheet" href="/css/vendor-bundle.min.f1ecf783c14edc00c9320c205831ad8e.css" media="print" onload="this.media='all'">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/academicons.min.css" integrity="sha512-W0xM4mr6dEP9nREo7Z9z+9X70wytKvMGeDsj7ps2+xg5QPrEBXC8tAW1IFnzjR6eoJ90JmCnFzerQJTLzIEHjA==" crossorigin="anonymous" media="print" onload="this.media='all'">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/styles/github.min.css" crossorigin="anonymous" title="hl-light" media="print" onload="this.media='all'">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/styles/dracula.min.css" crossorigin="anonymous" title="hl-dark" media="print" onload="this.media='all'" disabled>
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js" integrity="" crossorigin="anonymous" async></script>
<link rel="stylesheet" href="/css/wowchemy.eb67b44909a29cd9e91eebe9e783177c.css" />
<script async src="https://www.googletagmanager.com/gtag/js?id=3345897419"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
function trackOutboundLink(url, target) {
gtag('event', 'click', {
'event_category': 'outbound',
'event_label': url,
'transport_type': 'beacon',
'event_callback': function () {
if (target !== '_blank') {
document.location = url;
}
}
});
console.debug("Outbound link clicked: " + url);
}
function onClickCallback(event) {
if ((event.target.tagName !== 'A') || (event.target.host === window.location.host)) {
return;
}
trackOutboundLink(event.target, event.target.getAttribute('target'));
}
gtag('js', new Date());
gtag('config', '3345897419', {});
gtag('set', {'cookie_flags': 'SameSite=None;Secure'});
document.addEventListener('click', onClickCallback, false);
</script>
<link rel="manifest" href="/manifest.webmanifest" />
<link rel="icon" type="image/png" href="/media/icon_hu602ce00c64df696a8fc508a1a36adf94_21310_32x32_fill_lanczos_center_3.png" />
<link rel="apple-touch-icon" type="image/png" href="/media/icon_hu602ce00c64df696a8fc508a1a36adf94_21310_180x180_fill_lanczos_center_3.png" />
<link rel="canonical" href="https://oameye.github.io/post/eigenfunctions/" />
<meta property="twitter:card" content="summary_large_image" />
<meta property="twitter:site" content="@OrjanAmeye" />
<meta property="twitter:creator" content="@OrjanAmeye" />
<meta property="og:site_name" content="Orjan Ameye" />
<meta property="og:url" content="https://oameye.github.io/post/eigenfunctions/" />
<meta property="og:title" content="Eigenfunctions of the time independent Schrodinger equation | Orjan Ameye" />
<meta property="og:description" content="The eigenfunctions of the time independent Schrödinger equation are numerically computed by discretising with the finite difference method and using exact diagonalisation of sparse matrices." /><meta property="og:image" content="https://oameye.github.io/media/sharing.jpg" />
<meta property="twitter:image" content="https://oameye.github.io/media/sharing.jpg" /><meta property="og:locale" content="en-us" />
<meta
property="article:published_time"
content="2018-06-28T00:00:00+00:00"
/>
<meta property="article:modified_time" content="2018-06-28T00:00:00+00:00">
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BlogPosting",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "https://oameye.github.io/post/eigenfunctions/"
},
"headline": "Eigenfunctions of the time independent Schrodinger equation",
"datePublished": "2018-06-28T00:00:00Z",
"dateModified": "2018-06-28T00:00:00Z",
"author": {
"@type": "Person",
"name": "Orjan Ameye"
},
"publisher": {
"@type": "Organization",
"name": "Orjan Ameye",
"logo": {
"@type": "ImageObject",
"url": "https://oameye.github.io/media/icon_hu602ce00c64df696a8fc508a1a36adf94_21310_192x192_fill_lanczos_center_3.png"
}
},
"description": "The eigenfunctions of the time independent Schrödinger equation are numerically computed by discretising with the finite difference method and using exact diagonalisation of sparse matrices."
}
</script>
<title>Eigenfunctions of the time independent Schrodinger equation | Orjan Ameye</title>
</head>
<body id="top" data-spy="scroll" data-offset="70" data-target="#TableOfContents" class="page-wrapper " data-wc-page-id="d7188ac69d21942cfe546598244a73d7" >
<script src="/js/wowchemy-init.min.dff09253e40ffe282100440f62325070.js"></script>
<aside class="search-modal" id="search">
<div class="container">
<section class="search-header">
<div class="row no-gutters justify-content-between mb-3">
<div class="col-6">
<h1>Search</h1>
</div>
<div class="col-6 col-search-close">
<a class="js-search" href="#" aria-label="Close"><i class="fas fa-times-circle text-muted" aria-hidden="true"></i></a>
</div>
</div>
<div id="search-box">
<input name="q" id="search-query" placeholder="Search..." autocapitalize="off"
autocomplete="off" autocorrect="off" spellcheck="false" type="search" class="form-control"
aria-label="Search...">
</div>
</section>
<section class="section-search-results">
<div id="search-hits">
</div>
</section>
</div>
</aside>
<div class="page-header">
<header class="header--fixed">
<nav class="navbar navbar-expand-lg navbar-light compensate-for-scrollbar" id="navbar-main">
<div class="container-xl">
<div class="d-none d-lg-inline-flex">
<a class="navbar-brand" href="/">Orjan Ameye</a>
</div>
<button type="button" class="navbar-toggler" data-toggle="collapse"
data-target="#navbar-content" aria-controls="navbar-content" aria-expanded="false" aria-label="Toggle navigation">
<span><i class="fas fa-bars"></i></span>
</button>
<div class="navbar-brand-mobile-wrapper d-inline-flex d-lg-none">
<a class="navbar-brand" href="/">Orjan Ameye</a>
</div>
<div class="navbar-collapse main-menu-item collapse justify-content-start" id="navbar-content">
<ul class="navbar-nav d-md-inline-flex">
<li class="nav-item">
<a class="nav-link " href="/#about"><span>Home</span></a>
</li>
<li class="nav-item">
<a class="nav-link " href="/#posts"><span>Posts</span></a>
</li>
<li class="nav-item">
<a class="nav-link " href="/#contact"><span>Contact</span></a>
</li>
</ul>
</div>
<ul class="nav-icons navbar-nav flex-row ml-auto d-flex pl-md-2">
</ul>
</div>
</nav>
</header>
</div>
<div class="page-body">
<article class="article">
<div class="article-container pt-3">
<h1>Eigenfunctions of the time independent Schrodinger equation</h1>
<div class="article-metadata">
<span class="article-date">
Jun 28, 2018
</span>
<span class="middot-divider"></span>
<span class="article-reading-time">
9 min read
</span>
</div>
</div>
<div class="article-container">
<div class="article-style">
<p>The text and method is based on the following sources:</p>
<ul>
<li>Youtube, <em>2D Schrodinger Equation Numerical Solution in PYTHON</em>, (2022), Available at: <a href="https://www.youtube.com/watch?v=DF1SnjXZcbM&list=WL&index=8" target="_blank" rel="noopener">https://www.youtube.com/watch?v=DF1SnjXZcbM&list=WL&index=8</a> (Accessed: 6 March 2022).</li>
<li>Alexvas, <em>Discretization of Laplacian with boundary conditions</em>, (2017), Available at: <a href="https://scicomp.stackexchange.com/q/25976" target="_blank" rel="noopener">https://scicomp.stackexchange.com/q/25976</a> (Accessed: 6 March 2022).</li>
<li>Thomas H. Pulliam, David W. Zingg., <em>Fundamental Algorithms in Computational Fluid Dynamics</em>, (2014), Springer, Available at: <a href="https://link.springer.com/book/10.1007/978-3-319-05053-9" target="_blank" rel="noopener">https://link.springer.com/book/10.1007/978-3-319-05053-9</a> (Accessed: 6 March 2022).</li>
</ul>
<pre><code class="language-julia">using PyPlot, PyCall
using LinearAlgebra
using SparseArrays
using Arpack, KrylovKit
</code></pre>
<h2 id="two-dimensional-box">Two-dimensional box</h2>
<p>The goal is to solve the single particle Schrödinger equation in a two-dimensional box of length $2L$ of the Hamiltonian:
$$
\hat{h}=\frac{-\hbar^{2}}{2 m} \nabla^{2}+V(\mathbf{r}, t).
$$
The box can have a homogeneous Dirichlet boundary condition, i.e., the wave function evaluated at the border must vanish, or periodic boundary conditions. There can be a potential $V$ in the box. So let us a meshgrid of $\mathbf{x}$ and $\mathbf{y}$ coordinates.</p>
<pre><code class="language-julia">N = 100
L = 10.0
Δx² = (2*L/N)^2
function meshgrid(x::LinRange{Float64, Int64}, y::LinRange{Float64, Int64})::Tuple{Matrix{Float64}, Matrix{Float64}}
X = [x for _ in y, x in x]
Y = [y for y in y, _ in x]
X, Y
end
x = LinRange(-L, L, N)
y = LinRange(-L, L, N)
X, Y = meshgrid(x, y);
</code></pre>
<h2 id="potential">Potential</h2>
<p>The potential is chosen to be eightfold rotation symmetric quasicrystal, centered on $\mathbf{r}=0,$
$$
V(\mathbf{r})=V_{0} \sum_{k=1}^{4} \cos ^{2}\left(\mathbf{G}_{k} \cdot \mathbf{r}\right)
$$
where $V_{0}$ is the potential amplitude and the quantities $G_{k}$ are the lattice vectors of four mutually incoherent standing waves oriented at the angles $0^{\circ}, 45^{\circ}, 90^{\circ}$, and $135^{\circ}$, respectively. The lattice vectors have norm $\left|G_{k}\right|=\pi / a$.</p>
<pre><code class="language-julia">function get_potential(x, y, V₀)
return V₀*(cos(pi*x)^2 + cos(pi*√2/2*(x+y))^2 + cos(pi*y)^2 + cos(-pi/(√2)*(x-y))^2)
end
# def get_potential(x, y):
# return np.exp(-(x-0.3)**2/(2*0.1**2))*np.exp(-(y-0.3)**2/(2*0.1**2))
V = get_potential.(X,Y, 0.005)
fig = figure(figsize=(6.2,5))
contourf(X, Y, V, 50)
# pcolormesh(X, Y, V, cmap=:RdBu)
colorbar()
# plot_surface(X, Y, V)
</code></pre>
<p>
<figure >
<div class="d-flex justify-content-center">
<div class="w-100" ><img alt="png" srcset="
/post/eigenfunctions/output_6_0_hu3b0df9a8cf757933c6a55f90ff0a41bb_179880_aa274beb4957ff60b82c3f5c79717615.webp 400w,
/post/eigenfunctions/output_6_0_hu3b0df9a8cf757933c6a55f90ff0a41bb_179880_3cfffccfe2cc853c2e3785a09101425b.webp 760w,
/post/eigenfunctions/output_6_0_hu3b0df9a8cf757933c6a55f90ff0a41bb_179880_1200x1200_fit_q75_h2_lanczos_3.webp 1200w"
src="/post/eigenfunctions/output_6_0_hu3b0df9a8cf757933c6a55f90ff0a41bb_179880_aa274beb4957ff60b82c3f5c79717615.webp"
width="558"
height="434"
loading="lazy" data-zoomable /></div>
</div></figure>
</p>
<pre><code>PyObject <matplotlib.colorbar.Colorbar object at 0x0000000081FE1460>
</code></pre>
<h2 id="units">Units</h2>
<p>The Schrödinger equation is given by
$$ \left[\frac{-\hbar^{2}}{2 m} \nabla^{2}+V(\mathbf{r})\right] \psi(\mathbf{r}) = E\psi(\mathbf{r}),$$
Let us use the lattice spacing $a$ and the corresponding recoil energy $E_r = \pi^2\hbar^2/2ma^2$ as the space and energy units, respectively, such that we have
$$
\left[\frac{-\hbar^2}{2mE_ra^2} \tilde{\nabla}^{2}+\frac{V(\mathbf{\tilde{r}})}{E_r}\right] \psi(\mathbf{\tilde{r}}) = \left[\frac{-1}{\pi^2} \tilde{\nabla}^{2}+\tilde{V}_{0} \sum_{k=1}^{4} \cos ^{2}\left(\tilde{\mathbf{G}}_{k} \cdot \tilde{\mathbf{r}}\right)\right] \psi(\mathbf{\tilde{r}}) = \tilde{E}\psi(\mathbf{\tilde{r}}),
$$
where $|\tilde{\mathbf{G}}_{k}|=\pi$, $\tilde{\mathbf{r}} = \frac{\mathbf{r}}{a}$, and $\tilde{E}=\frac{E}{E_r}$.</p>
<h2 id="discretize-in-one-dimension">Discretize in one dimension</h2>
<p>Rest us to discretize our Hamiltonian. The idea can be easily explained by the following <strong>finite difference approximation</strong> of the second derivative in one dimension
$$ \frac{d^2 \psi}{dx^2} \approx \frac{\psi_{i+1}-2\psi_i + \psi_{i-1}}{\Delta x^2}.$$</p>
<h3 id="dirichlet-boundary-conditions">Dirichlet boundary conditions</h3>
<p>Suppose we have $M=4$ interior points and $a$ and $b$ two boundary points, a mesh with four interior points $\Delta x=2L /(M+1)$, represented as follows
\begin{align*}
&\qquad \ \ a \ \ \ \ 1 \ \ \ \ 2 \ \ \ \ 3 \ \ \ \, 4 \ \ \ \ b \\\
&x=-L \ - \ - \ - \ - \ \ L
\end{align*}
We impose Dirichlet boundary conditions, $u(-L)=u_{a}, u(L)=u_{b}$ and use the <strong>centered finite difference approximation</strong> at every point in the mesh. We arrive at the four equations:
\begin{align*}
\left(d_{x x} u\right)_{1} &=\frac{1}{\Delta x^{2}}\left(u_{a}-2 u_{1}+u_{2}\right) \qquad \left(d_{x x} u\right)_{2} =\frac{1}{\Delta x^{2}}\left(u_{1}-2 u_{2}+u_{3}\right) \\\\\\
\left(d_{x x} u\right)_{3} &=\frac{1}{\Delta x^{2}}\left(u_{2}-2 u_{3}+u_{4}\right) \qquad \left(d_{x x} u\right)_{4} =\frac{1}{\Delta x^{2}}\left(u_{3}-2 u_{4}+u_{b}\right)
\end{align*}
Introducing
\begin{align*}
\vec{u}=\left( \begin{array}{c} \psi_{1} \\\ \psi_{2} \\\ \psi_{3} \\\ \psi_{4} \end{array} \right)
\quad
(\overrightarrow{b c})=\frac{1}{\Delta x^{2}} \left( \begin{array}{c} \psi_{a} \\\ 0 \\\ 0 \\\ \psi_{b} \end{array} \right)
\quad
A=\frac{1}{\Delta x^{2}} \left( \begin{array}{rrrr} -2 & 1 & & \\\ 1 & -2 & 1 & \\\ & 1 & -2 & 1 \\\ & & 1 & -2 \end{array} \right)
\end{align*}
we can rewrite in matrix form as
\begin{align*}
\frac{d^2 \psi}{dx^2} =\frac{1}{\Delta x^{2}}D= A \vec{\psi}+(\overrightarrow{b c})
\end{align*}</p>
<h3 id="periodic-boundary-conditions">Periodic boundary conditions</h3>
<p>$\color{red}{\text{This subsection has to tested and worked out. First try did not work.}}$</p>
<p>Suppose we have $M=8$ points on a linear <strong>periodic</strong> mesh, represented as follows
\begin{align*}
&\cdots \ \ \ 7 \ \ \ \ 8 \ \ \ \ \ \ a \ \ \ \ 1 \ \ \ \ 2 \ \ \ \ 3 \ \ \ \ 4 \ \ \ \ b \ \ \ \ 1 \ \ \ \ 2 \ \ \ \cdots \\\
&x= \ - \ \ - \ \ -L \ \ - \ \ - \ \ - \ \ - \ \ L \ \ - \ \ -
\end{align*}
where we have that $\psi(L)=\psi(-L)$. It can be shown that the matrix representation is modified by
\begin{align*}
\frac{d^2 \psi}{dx^2} =\frac{1}{\Delta x^{2}}D_p=\frac{1}{\Delta x^{2}} \left( \begin{array}{rrrr} -2 & 1 & & 1 \\\ 1 & -2 & 1 & \\\ & 1 & -2 & 1 \\\ 1 & & 1 & -2 \end{array} \right)
\end{align*}</p>
<h2 id="discretize-in-two-dimensions">Discretize in two dimensions</h2>
<p>In <strong>two dimensions</strong>, the wavefunction is not a vector anymore but a matrix. However, we would like to write it back as vector via the transformation
$$
\left( \begin{array}{rrrr} \psi_{11} & \psi_{12} & \cdots & \psi_{1N} \\\ \psi_{21} & \psi_{22} & \cdots & \psi_{2N} \\\ \vdots & \vdots & \ddots & \vdots \\\ \psi_{N1} & \psi_{N2} & \cdots & \psi_{NN} \end{array} \right) \rightarrow \left( \begin{array}{c} \psi_{11} \\\ \psi_{12} \\\ \vdots \\\ \psi_{NN} \end{array} \right)
$$
The second derivative finite difference matrix must than be written as
$$
\frac{\partial^2 \psi}{\partial x^2} = \frac{1}{\Delta x^{2}} I \otimes D = \frac{1}{\Delta x^{2}} \left( \begin{array}{rrr} D & & \\\ & \ddots & \\\ & & D\end{array} \right)
$$
where $\otimes$ is the <strong>Kronecker product</strong>. The <strong>2D Laplacian</strong> can than be written as
$$
\nabla^{2} = \frac{\partial^2 \psi}{\partial x^2} + \frac{\partial^2 \psi}{\partial y^2} = \frac{1}{\Delta x^{2}} (I \otimes D + D \otimes I) = \frac{1}{\Delta x^{2}} D\oplus D
$$
where $\oplus$ is the <strong>Kronecker sum</strong>, and we used that we discretized space as a <strong>squared grid</strong>, i.e. $\Delta x^{2}=\Delta y^{2}$.</p>
<h2 id="hamiltonian">Hamiltonian</h2>
<p>Let us assume the homogeneous Dirichlet Boundary conditions $\psi(L, y) = \psi(-L, y) = \psi(x, L) = \psi(x, -L) = 0$. The <strong>discretized Schrödinger equation</strong> can then be written as
$$
\left[-\frac{1}{\pi^2}(D \oplus D) + \Delta x^2 \tilde{V} \right] \psi = \left( \Delta x^2 \tilde{E}\right) \psi,
$$
where $D$ has -2 on the main diagonal and 1 on the two neighboring diagonals and $\psi$ is a vector. One could define the potential in units of $\Delta x^2$; in other words <code>get_potential</code> actually returns $\Delta x^2 V$. However, we will leave $\Delta x^2$ in the kinetic term.
Now we construct
$$
\hat{h} = -\frac{1}{\Delta x^{2}\pi^2} D \oplus D + \tilde{V}
$$
such that the corresponding eigenvalues $\tilde{E}$ are in units of recoil energy $E_r$.
Let $T=-\frac{1}{\Delta x^{2}\pi^2} D \oplus D$ and $U = V$</p>
<pre><code class="language-julia">diag = ones(N); # vector of ones
diags = Vector([diag[begin:end-1], -2*diag, diag[begin:end-1]]); # vector of vectors of the diagonals
D = sparse(Tridiagonal(diags...)) # creates the discretised 2nd derivative
T = -1/(Δx²*pi^2) * (kron(D, sparse(I,N,N)) + kron(sparse(I,N,N), D)) #N**2 x N**2 matrix
U = spdiagm(reshape(V, N^2))
H = T+U;
</code></pre>
<p>Here we used the package <code>SparseArrays.jl</code> to make the computations faster. <strong>Sparse arrays</strong> are arrays that contain enough zeros that storing them in a special data structure leads to savings in space and execution time, compared to dense arrays.</p>
<h2 id="eigenvectors-and-eigenvalues">Eigenvectors and eigenvalues</h2>
<p>Now that we constructed our discretized Hamiltonian we can just exactly diagonalize our Hamiltonian to find the <strong>eigenvalues</strong> and <strong>eigenvector</strong>. We shall to this with the package <code>Arpack.jl</code> which is a <em>Julia</em> wrapper to a <em>FORTRAN 77</em> library designed to compute a few eigenvalues and corresponding eigenvectors of large sparse or structured matrices, using the <strong>Implicitly Restarted Arnoldi Method</strong> (IRAM) or, in the case of symmetric matrices, the corresponding variant of the <strong>Lanczos algorithm</strong>. Both are classified as <em>Krylov subspace based algorithms</em> (see wikipedia). It is used by many popular numerical computing environments such as <em>SciPy</em>, <em>Mathematica</em>, <em>GNU Octave</em> and <em>MATLAB</em> to provide this functionality.</p>
<p>We use the <code>eigs</code> function where <code>nev</code> specifies how many eigenvalues and eigenvectors we want and <code>which</code> specifies the type of eigenvalues to compute. For my purposes I only need the ground state wave function.</p>
<p>Alternatively, one could use <code>KrylovKit.jl</code>, a native Julia package collecting a number of Krylov-based algorithms for linear problems, singular value and eigenvalue problems and the application of functions of linear maps or operators to vectors. With <code>KrylovKit.jl</code> I manage to find better results if when I increase the number of point $N$. My theory is that it, as black box solver, uses another method above a certain threshold $N^*$, whereas <code>Arpack.jl</code> sticks to the same method and hence gives worse results.</p>
<pre><code class="language-julia"># eigenvalues, eigenvectors = eigs(H, nev=1, which=:SM);
_, vecs, _ = eigsolve(H, 1, :SR);
# vecs[1]
</code></pre>
<p>As we constructed the Hamiltonian to be a $N^2 \times N^2$ so that $\psi$ could be a vector, we have to reshape the eigenvectors back to a $N \times N$ matrix.</p>
<pre><code class="language-julia">function get_e(n::Int64)
return reshape(vecs[1]', N, N)
end;
</code></pre>
<pre><code class="language-julia">figure(figsize=(6.2,5))
pcolormesh(X, Y, get_e(0)^2, cmap=:RdBu)
colorbar()
# contourf(X, Y, get_e(0)^2, 100)
</code></pre>
<p>
<figure >
<div class="d-flex justify-content-center">
<div class="w-100" ><img alt="png" srcset="
/post/eigenfunctions/output_20_0_hufc67467fdee818d97001458e24b0f472_36038_983d3b93f7e9c05263dc7cf5df085168.webp 400w,
/post/eigenfunctions/output_20_0_hufc67467fdee818d97001458e24b0f472_36038_a23be35e0f06b0cec3de224d533613f6.webp 760w,
/post/eigenfunctions/output_20_0_hufc67467fdee818d97001458e24b0f472_36038_1200x1200_fit_q75_h2_lanczos_3.webp 1200w"
src="/post/eigenfunctions/output_20_0_hufc67467fdee818d97001458e24b0f472_36038_983d3b93f7e9c05263dc7cf5df085168.webp"
width="558"
height="432"
loading="lazy" data-zoomable /></div>
</div></figure>
</p>
<pre><code>PyObject <matplotlib.colorbar.Colorbar object at 0x0000000006C91580>
</code></pre>
<h2 id="summary">Summary</h2>
<pre><code class="language-julia">using PyPlot, PyCall
using LinearAlgebra
using SparseArrays
using Arpack, KrylovKit
function meshgrid(x::LinRange{Float64, Int64}, y::LinRange{Float64, Int64})::Tuple{Matrix{Float64}, Matrix{Float64}}
X = [x for _ in y, x in x]
Y = [y for y in y, _ in x]
X, Y
end
function QC(x::Float64, y::Float64, V₀::Float64)::Float64
return V₀*(cos(pi*x)^2 + cos(pi*√2/2*(x+y))^2 + cos(pi*y)^2 + cos(-pi/(√2)*(x-y))^2)
end
function free(x::Float64, y::Float64, V₀::Float64)::Float64
return V₀*(0*x+0*y)
end
function PC(x::Float64, y::Float64, V₀::Float64)::Float64
return V₀*(sin(pi*x)^2+sin(pi*y)^2)
end
function eigenfunctionDBCArpack(V::Matrix{Float64}, L::Float64, N::Int64)
Δx² = (2*L/N)^2
# creates the discretised 2nd derivative
D = sparse(Tridiagonal(ones(N-1), -2*ones(N), ones(N-1)))
# N**2 x N**2 matrix
T = -1/(Δx²*pi^2) * (kron(D, sparse(I,N,N)) + kron(sparse(I,N,N), D))
U = spdiagm(reshape(V, N^2))
H = T + U;
_, eigenvector = eigs(H, nev=1, which=:SM);
return reshape(eigenvector', N, N)
end
function eigenfunctionDBCKrylov(V::Matrix{Float64}, L::Float64, N::Int64)
Δx² = (2*L/N)^2
# creates the discretised 2nd derivative
D = sparse(Tridiagonal(ones(N-1), -2*ones(N), ones(N-1)))
# N**2 x N**2 matrix