{"id":1300,"date":"2018-11-10T16:59:49","date_gmt":"2018-11-10T16:59:49","guid":{"rendered":"http:\/\/second-tech.com\/wordpress\/?p=1300"},"modified":"2019-07-09T09:23:40","modified_gmt":"2019-07-09T09:23:40","slug":"finite-differences-and-second-quantization","status":"publish","type":"post","link":"http:\/\/second-tech.com\/wordpress\/index.php\/2018\/11\/10\/finite-differences-and-second-quantization\/","title":{"rendered":"Finite differences and second quantization"},"content":{"rendered":"<p><i>Most recent TBTK release at the time of writing: v1.0.3<\/i><\/p>\n<p>Single-particle quantum mechanics is usually formulated using a differential equation such as the Schr\u00f6dinger equation. The simplest way to solve this numerically is through the use of finite differences. While TBTK is designed for discrete problems formulated on second quantized form, this includes the possibility to work with finite difference schemes. In this post, we, therefore, go through the basic principles of finite differences and how to arrive at a discretized version of the Schr\u00f6dinger equation. We then describe how to translate this to a second quantized form.<\/p>\n<p>While we focus on the Schr\u00f6dinger equation, the methods discussed here can be applied to any finite difference scheme and should therefore be of broad interest also beyond quantum mechanics. In particular, the ease with which models are extended beyond one dimension should be of interest for anyone implementing finite difference calculations in general.<\/p>\n<div class=\"a-single a-4\"><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\r\n<ins class=\"adsbygoogle\"\r\n     style=\"display:block; text-align:center;\"\r\n     data-ad-layout=\"in-article\"\r\n     data-ad-format=\"fluid\"\r\n     data-ad-client=\"ca-pub-3756520172792312\"\r\n     data-ad-slot=\"9656949358\"><\/ins>\r\n<script>\r\n     (adsbygoogle = window.adsbygoogle || []).push({});\r\n<\/script><\/div>\n<h2>Finite differences<\/h2>\n<h3>First derivative<\/h3>\n<p>Finite differences are simple to understand if we remind ourselves of the definition of the derivative of a function,<\/p>\n<p class=\"ql-center-displayed-equation\" style=\"line-height: 38px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-4e5b7b4edc4b258a9f1651b32a05d14d_l3.png\" height=\"38\" width=\"301\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#091; &#92;&#102;&#114;&#97;&#99;&#123;&#100;&#102;&#40;&#120;&#41;&#125;&#123;&#100;&#120;&#125;&#32;&#61;&#32;&#92;&#108;&#105;&#109;&#95;&#123;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#92;&#114;&#105;&#103;&#104;&#116;&#97;&#114;&#114;&#111;&#119;&#32;&#48;&#125;&#92;&#102;&#114;&#97;&#99;&#123;&#102;&#40;&#120;&#32;&#43;&#32;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#41;&#32;&#45;&#32;&#102;&#40;&#120;&#32;&#45;&#32;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#41;&#125;&#123;&#50;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#125;&#46; &#92;&#093;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>\n<p>As the name implies, finite differences result when the derivative is instead approximated by<\/p>\n<p class=\"ql-center-displayed-equation\" style=\"line-height: 38px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-6eaf348106089f6af8d0b1e511a86fcb_l3.png\" height=\"38\" width=\"258\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#091; &#92;&#102;&#114;&#97;&#99;&#123;&#100;&#102;&#40;&#120;&#41;&#125;&#123;&#100;&#120;&#125;&#32;&#92;&#97;&#112;&#112;&#114;&#111;&#120;&#32;&#92;&#102;&#114;&#97;&#99;&#123;&#102;&#40;&#120;&#32;&#43;&#32;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#41;&#32;&#45;&#32;&#102;&#40;&#120;&#32;&#45;&#32;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#41;&#125;&#123;&#50;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#125;&#44; &#92;&#093;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>\n<p>for some finite discretization length <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-3895405919830c2f05932026bfa4077b_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"25\" style=\"vertical-align: 0px;\"\/>.<\/p>\n<p>The finite difference scheme naturally defines a uniform grid containing the points <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-ae36b4ce098ba09ff69c20c26de17c34_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#120;&#95;&#110;&#32;&#61;&#32;&#110;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"79\" style=\"vertical-align: -3px;\"\/> for integer <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-a63eb5ff0272d3119fa684be6e7acce8_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#110;\" title=\"Rendered by QuickLaTeX.com\" height=\"8\" width=\"11\" style=\"vertical-align: 0px;\"\/>. Moreover, since the finite difference approximation should be understood to be valid for each of these points, it really is a set of linear equations of the form<\/p>\n<p class=\"ql-center-displayed-equation\" style=\"line-height: 118px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-bc3b6122c3f8797d780bfa466c093aa6_l3.png\" height=\"118\" width=\"245\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#091; &#92;&#98;&#101;&#103;&#105;&#110;&#123;&#97;&#108;&#105;&#103;&#110;&#101;&#100;&#125; &#46;&#46;&#46;&#32;&#38;&#32;&#46;&#46;&#46;&#92;&#92; &#92;&#102;&#114;&#97;&#99;&#123;&#100;&#102;&#40;&#120;&#95;&#110;&#41;&#125;&#123;&#100;&#120;&#125;&#32;&#38;&#92;&#97;&#112;&#112;&#114;&#111;&#120;&#32;&#92;&#102;&#114;&#97;&#99;&#123;&#102;&#40;&#120;&#95;&#123;&#110;&#43;&#49;&#125;&#41;&#32;&#45;&#32;&#102;&#40;&#120;&#95;&#123;&#110;&#45;&#49;&#125;&#41;&#125;&#123;&#50;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#125;&#44;&#92;&#92; &#92;&#102;&#114;&#97;&#99;&#123;&#100;&#102;&#40;&#120;&#95;&#123;&#110;&#43;&#49;&#125;&#41;&#125;&#123;&#100;&#120;&#125;&#32;&#38;&#92;&#97;&#112;&#112;&#114;&#111;&#120;&#32;&#92;&#102;&#114;&#97;&#99;&#123;&#102;&#40;&#120;&#95;&#123;&#110;&#43;&#50;&#125;&#41;&#32;&#45;&#32;&#102;&#40;&#120;&#95;&#110;&#41;&#125;&#123;&#50;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#125;&#44;&#92;&#92; &#46;&#46;&#46;&#32;&#38;&#32;&#46;&#46;&#46; &#92;&#101;&#110;&#100;&#123;&#97;&#108;&#105;&#103;&#110;&#101;&#100;&#125; &#92;&#093;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>\n<p>Using matrix notation, this can also be expressed as<\/p>\n<p class=\"ql-center-displayed-equation\" style=\"line-height: 97px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-c3f75bb9206cd612679e2c3e39cf8a1f_l3.png\" height=\"97\" width=\"262\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#091;&#92;&#108;&#101;&#102;&#116;&#091;&#92;&#98;&#101;&#103;&#105;&#110;&#123;&#97;&#114;&#114;&#97;&#121;&#125;&#123;&#99;&#125; &#46;&#46;&#46;&#92;&#92; &#92;&#102;&#114;&#97;&#99;&#123;&#100;&#102;&#40;&#120;&#95;&#110;&#41;&#125;&#123;&#100;&#120;&#125;&#92;&#92; &#92;&#102;&#114;&#97;&#99;&#123;&#100;&#102;&#40;&#120;&#95;&#123;&#110;&#43;&#49;&#125;&#41;&#125;&#123;&#100;&#120;&#125;&#92;&#92; &#46;&#46;&#46; &#92;&#101;&#110;&#100;&#123;&#97;&#114;&#114;&#97;&#121;&#125;&#92;&#114;&#105;&#103;&#104;&#116;&#093;&#32;&#92;&#97;&#112;&#112;&#114;&#111;&#120;&#32;&#68;&#94;&#123;&#40;&#49;&#41;&#125;&#92;&#108;&#101;&#102;&#116;&#091;&#92;&#98;&#101;&#103;&#105;&#110;&#123;&#97;&#114;&#114;&#97;&#121;&#125;&#123;&#99;&#125; &#46;&#46;&#46;&#92;&#92; &#102;&#40;&#120;&#95;&#110;&#41;&#92;&#92; &#102;&#40;&#120;&#95;&#123;&#110;&#43;&#49;&#125;&#41;&#92;&#92; &#46;&#46;&#46; &#92;&#101;&#110;&#100;&#123;&#97;&#114;&#114;&#97;&#121;&#125;&#92;&#114;&#105;&#103;&#104;&#116;&#093;&#44; &#92;&#093;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>\n<p>where<\/p>\n<p class=\"ql-center-displayed-equation\" style=\"line-height: 86px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-d12f8ad72b2c77d0dd06ce24371e9770_l3.png\" height=\"86\" width=\"330\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#091; &#68;&#94;&#123;&#40;&#49;&#41;&#125;&#32;&#61;&#32;&#92;&#102;&#114;&#97;&#99;&#123;&#49;&#125;&#123;&#50;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#125;&#92;&#108;&#101;&#102;&#116;&#091;&#92;&#98;&#101;&#103;&#105;&#110;&#123;&#97;&#114;&#114;&#97;&#121;&#125;&#123;&#99;&#99;&#99;&#99;&#99;&#99;&#125; &#46;&#46;&#46;&#32;&#38;&#32;&#46;&#46;&#46;&#32;&#38;&#32;&#46;&#46;&#46;&#32;&#38;&#32;&#46;&#46;&#46;&#32;&#38;&#32;&#46;&#46;&#46;&#32;&#38;&#32;&#46;&#46;&#46;&#92;&#92; &#46;&#46;&#46;&#32;&#38;&#32;&#45;&#49;&#32;&#38;&#32;&#48;&#32;&#38;&#32;&#49;&#32;&#38;&#32;&#48;&#32;&#38;&#32;&#46;&#46;&#46;&#92;&#92; &#46;&#46;&#46;&#32;&#38;&#32;&#48;&#32;&#38;&#32;&#45;&#49;&#32;&#38;&#32;&#48;&#32;&#38;&#32;&#49;&#32;&#38;&#32;&#46;&#46;&#46;&#92;&#92; &#46;&#46;&#46;&#32;&#38;&#32;&#46;&#46;&#46;&#32;&#38;&#32;&#46;&#46;&#46;&#32;&#38;&#32;&#46;&#46;&#46;&#32;&#38;&#32;&#46;&#46;&#46;&#32;&#38;&#32;&#46;&#46;&#46; &#92;&#101;&#110;&#100;&#123;&#97;&#114;&#114;&#97;&#121;&#125;&#92;&#114;&#105;&#103;&#104;&#116;&#093;&#46;&#92;&#093;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>\n<p>Here <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-4875a70777521f0d9f6f2f7062dd5b5d_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#45;&#49;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"21\" style=\"vertical-align: -1px;\"\/> and <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-21b5b4cbe9a10b6d847eeb4265b99898_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#49;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"7\" style=\"vertical-align: -1px;\"\/> appear right below and above the diagonal, respectively.<\/p>\n<p>For the problem to be possible to put into a computer, the number of discretization points need to be finite, for example <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-0c42b4a650b613575768b16274d0ebdb_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#123;&#120;&#95;&#48;&#44;&#32;&#46;&#46;&#46;&#44;&#32;&#120;&#95;&#123;&#78;&#45;&#49;&#125;&#92;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"18\" width=\"105\" style=\"vertical-align: -5px;\"\/> for some finite <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-b57494e2a3f4838b8025f0fe6e89db99_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#78;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"16\" style=\"vertical-align: 0px;\"\/>. The matrix therefore necessarily have to be truncated, which means that the first and last row in fact corresponds to<\/p>\n<p class=\"ql-center-displayed-equation\" style=\"line-height: 82px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-4537d9e33c519464c7cf3fee10af2df9_l3.png\" height=\"82\" width=\"201\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#091;&#92;&#98;&#101;&#103;&#105;&#110;&#123;&#97;&#108;&#105;&#103;&#110;&#101;&#100;&#125; &#92;&#102;&#114;&#97;&#99;&#123;&#100;&#102;&#40;&#120;&#95;&#123;&#48;&#125;&#41;&#125;&#123;&#100;&#120;&#125;&#32;&#38;&#92;&#97;&#112;&#112;&#114;&#111;&#120;&#32;&#92;&#102;&#114;&#97;&#99;&#123;&#102;&#40;&#120;&#95;&#49;&#41;&#32;&#45;&#32;&#48;&#125;&#123;&#50;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#125;&#44;&#92;&#92; &#92;&#102;&#114;&#97;&#99;&#123;&#100;&#102;&#40;&#120;&#95;&#123;&#78;&#45;&#49;&#125;&#41;&#125;&#123;&#100;&#120;&#125;&#32;&#38;&#92;&#97;&#112;&#112;&#114;&#111;&#120;&#32;&#92;&#102;&#114;&#97;&#99;&#123;&#48;&#32;&#45;&#32;&#102;&#40;&#120;&#95;&#123;&#78;&#45;&#50;&#125;&#41;&#125;&#123;&#50;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#125;&#46; &#92;&#101;&#110;&#100;&#123;&#97;&#108;&#105;&#103;&#110;&#101;&#100;&#125;&#92;&#093;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>\n<p>That is, by simply truncating the matrix we imply the boundary conditions <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-2155cb3994c8e45b3e4fef7b22128d9d_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#102;&#40;&#120;&#95;&#123;&#45;&#49;&#125;&#41;&#32;&#61;&#32;&#102;&#40;&#120;&#95;&#123;&#78;&#125;&#41;&#32;&#61;&#32;&#48;\" title=\"Rendered by QuickLaTeX.com\" height=\"18\" width=\"157\" style=\"vertical-align: -4px;\"\/>. Other boundary conditions can be added back into the formulation, but for simplicity we will consider these boundary conditions here.<\/p>\n<h3>Forward, centered, and backward differences<\/h3>\n<p>To be more specific, the finite difference scheme above is called a centered difference since it is formulated symmetrically around the point at which the derivative is approximated. For functions with well defined derivative we could equivalently have formulated the derivative using any of the three expressions<\/p>\n<p class=\"ql-center-displayed-equation\" style=\"line-height: 129px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-ddc79e8e373525ac60051f252a75c23d_l3.png\" height=\"129\" width=\"301\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#091;&#92;&#98;&#101;&#103;&#105;&#110;&#123;&#97;&#108;&#105;&#103;&#110;&#101;&#100;&#125; &#92;&#102;&#114;&#97;&#99;&#123;&#100;&#102;&#40;&#120;&#41;&#125;&#123;&#100;&#120;&#125;&#32;&#38;&#61;&#32;&#92;&#108;&#105;&#109;&#95;&#123;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#32;&#92;&#114;&#105;&#103;&#104;&#116;&#97;&#114;&#114;&#111;&#119;&#32;&#48;&#125;&#92;&#102;&#114;&#97;&#99;&#123;&#102;&#40;&#120;&#32;&#43;&#32;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#41;&#32;&#45;&#32;&#102;&#40;&#120;&#41;&#125;&#123;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#125;&#44;&#92;&#92; &#92;&#102;&#114;&#97;&#99;&#123;&#100;&#102;&#40;&#120;&#41;&#125;&#123;&#100;&#120;&#125;&#32;&#38;&#61;&#32;&#92;&#108;&#105;&#109;&#95;&#123;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#32;&#92;&#114;&#105;&#103;&#104;&#116;&#97;&#114;&#114;&#111;&#119;&#32;&#48;&#125;&#92;&#102;&#114;&#97;&#99;&#123;&#102;&#40;&#120;&#32;&#43;&#32;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#41;&#32;&#45;&#32;&#102;&#40;&#120;&#32;&#45;&#32;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#41;&#125;&#123;&#50;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#125;&#44;&#92;&#92; &#92;&#102;&#114;&#97;&#99;&#123;&#100;&#102;&#40;&#120;&#41;&#125;&#123;&#100;&#120;&#125;&#32;&#38;&#61;&#32;&#92;&#108;&#105;&#109;&#95;&#123;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#32;&#92;&#114;&#105;&#103;&#104;&#116;&#97;&#114;&#114;&#111;&#119;&#32;&#48;&#125;&#92;&#102;&#114;&#97;&#99;&#123;&#102;&#40;&#120;&#41;&#32;&#45;&#32;&#102;&#40;&#120;&#32;&#45;&#32;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#41;&#125;&#123;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#125;&#46; &#92;&#101;&#110;&#100;&#123;&#97;&#108;&#105;&#103;&#110;&#101;&#100;&#125;&#92;&#093;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>\n<p>However, when working with finite differences the three expressions do differ and are known as the forward, centered, and backward difference, respectively.<\/p>\n<p>If we go through the same steps as for the centered difference above also for the forward and backward differences, we arrive at matrices that are multiplied by a factor <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-66601065bcd9ab849a385ba85eed976b_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#49;&#47;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;\" title=\"Rendered by QuickLaTeX.com\" height=\"18\" width=\"42\" style=\"vertical-align: -5px;\"\/> instead of <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-42070ec6180ed62ecedd6f50c7d53c58_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#49;&#47;&#50;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;\" title=\"Rendered by QuickLaTeX.com\" height=\"18\" width=\"51\" style=\"vertical-align: -5px;\"\/>. Moreover, the two matrices also have the -1 and 1 off-diagonal entries moved onto the diagonal, respectively. This leads to a different type of boundary conditions once the matrix is truncated. However, here we will not be interested in the finite difference expression for the first derivative directly. Rather, the forward and backward differences are of interest to us since they allow us to arrive at a simple expression for the second derivative.<\/p>\n<h3>Second derivative<\/h3>\n<p>The second derivative of a function is given by<\/p>\n<p class=\"ql-center-displayed-equation\" style=\"line-height: 49px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-965f4a4865286f63971c9b12d3b1f7b1_l3.png\" height=\"49\" width=\"282\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#091; &#92;&#102;&#114;&#97;&#99;&#123;&#100;&#94;&#50;&#102;&#40;&#120;&#41;&#125;&#123;&#100;&#120;&#94;&#50;&#125;&#32;&#61;&#32;&#92;&#108;&#105;&#109;&#95;&#123;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#32;&#92;&#114;&#105;&#103;&#104;&#116;&#97;&#114;&#114;&#111;&#119;&#32;&#48;&#125;&#92;&#102;&#114;&#97;&#99;&#123;&#92;&#102;&#114;&#97;&#99;&#123;&#100;&#102;&#40;&#120;&#32;&#43;&#32;&#92;&#102;&#114;&#97;&#99;&#123;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#125;&#123;&#50;&#125;&#41;&#125;&#123;&#100;&#120;&#125;&#32;&#45;&#32;&#92;&#102;&#114;&#97;&#99;&#123;&#100;&#102;&#40;&#120;&#32;&#45;&#32;&#92;&#102;&#114;&#97;&#99;&#123;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#125;&#123;&#50;&#125;&#41;&#125;&#123;&#100;&#120;&#125;&#125;&#123;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#125;&#46; &#92;&#093;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>\n<p>When discretized, the first term in this expression can either be understood as the centered difference at <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-1ae9547a9cbdd90afff35b25d99821c7_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#120;&#32;&#43;&#32;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#47;&#50;\" title=\"Rendered by QuickLaTeX.com\" height=\"18\" width=\"74\" style=\"vertical-align: -5px;\"\/>, or as the forward difference at <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-1b9fbfb207b6d17d74b33c6d8342a1a4_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#120;\" title=\"Rendered by QuickLaTeX.com\" height=\"8\" width=\"10\" style=\"vertical-align: 0px;\"\/>. Similarly the second term can be understood as either the centered difference at <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-b5e08f0ccfa10b5506f8a9080c3375a9_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#120;&#32;&#45;&#32;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#47;&#50;\" title=\"Rendered by QuickLaTeX.com\" height=\"18\" width=\"74\" style=\"vertical-align: -5px;\"\/>, or as the backward difference at <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-1b9fbfb207b6d17d74b33c6d8342a1a4_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#120;\" title=\"Rendered by QuickLaTeX.com\" height=\"8\" width=\"10\" style=\"vertical-align: 0px;\"\/>.<\/p>\n<p>It is helpful to consider the first and second term to be the forward and backward differences, respectively, since this allows us to stay on the lattice <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-462af72145ee6e7e7f8f17f35c3aeaf2_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#120;&#95;&#123;&#110;&#125;&#32;&#61;&#32;&#110;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"79\" style=\"vertical-align: -3px;\"\/>. Plugging in the forward and backward differences and removing the limit, we get<\/p>\n<p class=\"ql-center-displayed-equation\" style=\"line-height: 39px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-15e7c67213cb2d1677be621684170067_l3.png\" height=\"39\" width=\"334\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#091; &#92;&#102;&#114;&#97;&#99;&#123;&#100;&#94;&#50;&#102;&#40;&#120;&#41;&#125;&#123;&#100;&#120;&#94;&#50;&#125;&#32;&#92;&#97;&#112;&#112;&#114;&#111;&#120;&#32;&#92;&#102;&#114;&#97;&#99;&#123;&#102;&#40;&#120;&#32;&#43;&#32;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#41;&#32;&#45;&#32;&#50;&#102;&#40;&#120;&#41;&#32;&#43;&#32;&#102;&#40;&#120;&#32;&#45;&#32;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#41;&#125;&#123;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#94;&#50;&#125;&#46; &#92;&#093;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>\n<p>Rewriting this on matrix form we then arrive at<\/p>\n<p class=\"ql-center-displayed-equation\" style=\"line-height: 97px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-670d76e00be6e69d68f6eba8f70e4e69_l3.png\" height=\"97\" width=\"270\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#091;&#92;&#108;&#101;&#102;&#116;&#091;&#92;&#98;&#101;&#103;&#105;&#110;&#123;&#97;&#114;&#114;&#97;&#121;&#125;&#123;&#99;&#125; &#46;&#46;&#46;&#92;&#92; &#92;&#102;&#114;&#97;&#99;&#123;&#100;&#94;&#50;&#102;&#40;&#120;&#95;&#110;&#41;&#125;&#123;&#100;&#120;&#94;&#50;&#125;&#92;&#92; &#92;&#102;&#114;&#97;&#99;&#123;&#100;&#94;&#50;&#102;&#40;&#120;&#95;&#123;&#110;&#43;&#49;&#125;&#41;&#125;&#123;&#100;&#120;&#94;&#50;&#125;&#92;&#92; &#46;&#46;&#46; &#92;&#101;&#110;&#100;&#123;&#97;&#114;&#114;&#97;&#121;&#125;&#92;&#114;&#105;&#103;&#104;&#116;&#093;&#32;&#92;&#97;&#112;&#112;&#114;&#111;&#120;&#32;&#68;&#94;&#123;&#40;&#50;&#41;&#125;&#92;&#108;&#101;&#102;&#116;&#091;&#92;&#98;&#101;&#103;&#105;&#110;&#123;&#97;&#114;&#114;&#97;&#121;&#125;&#123;&#99;&#125; &#46;&#46;&#46;&#92;&#92; &#102;&#40;&#120;&#95;&#110;&#41;&#92;&#92; &#102;&#40;&#120;&#95;&#123;&#110;&#43;&#49;&#125;&#41;&#92;&#92; &#46;&#46;&#46; &#92;&#101;&#110;&#100;&#123;&#97;&#114;&#114;&#97;&#121;&#125;&#92;&#114;&#105;&#103;&#104;&#116;&#093;&#44; &#92;&#093;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>\n<p>where<\/p>\n<p class=\"ql-center-displayed-equation\" style=\"line-height: 86px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-8071a3931503033ac032e660a669dc01_l3.png\" height=\"86\" width=\"329\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#091; &#68;&#94;&#123;&#40;&#50;&#41;&#125;&#32;&#61;&#32;&#92;&#102;&#114;&#97;&#99;&#123;&#49;&#125;&#123;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#94;&#50;&#125;&#92;&#108;&#101;&#102;&#116;&#091;&#92;&#98;&#101;&#103;&#105;&#110;&#123;&#97;&#114;&#114;&#97;&#121;&#125;&#123;&#99;&#99;&#99;&#99;&#99;&#99;&#125; &#46;&#46;&#46;&#32;&#38;&#32;&#46;&#46;&#46;&#32;&#38;&#32;&#46;&#46;&#46;&#32;&#38;&#32;&#46;&#46;&#46;&#32;&#38;&#32;&#46;&#46;&#46;&#32;&#38;&#32;&#46;&#46;&#46;&#92;&#92; &#46;&#46;&#46;&#32;&#38;&#32;&#49;&#32;&#38;&#32;&#45;&#50;&#32;&#38;&#32;&#49;&#32;&#38;&#32;&#48;&#32;&#38;&#32;&#46;&#46;&#46;&#92;&#92; &#46;&#46;&#46;&#32;&#38;&#32;&#48;&#32;&#38;&#32;&#49;&#32;&#38;&#32;&#45;&#50;&#32;&#38;&#32;&#49;&#32;&#38;&#32;&#46;&#46;&#46;&#92;&#92; &#46;&#46;&#46;&#32;&#38;&#32;&#46;&#46;&#46;&#32;&#38;&#32;&#46;&#46;&#46;&#32;&#38;&#32;&#46;&#46;&#46;&#32;&#38;&#32;&#46;&#46;&#46;&#32;&#38;&#32;&#46;&#46;&#46; &#92;&#101;&#110;&#100;&#123;&#97;&#114;&#114;&#97;&#121;&#125;&#92;&#114;&#105;&#103;&#104;&#116;&#093;&#46;&#92;&#093;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>\n<p>Here the -2 entries fall on the diagonal. Truncating this matrix implies the same boundary conditions <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-2155cb3994c8e45b3e4fef7b22128d9d_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#102;&#40;&#120;&#95;&#123;&#45;&#49;&#125;&#41;&#32;&#61;&#32;&#102;&#40;&#120;&#95;&#123;&#78;&#125;&#41;&#32;&#61;&#32;&#48;\" title=\"Rendered by QuickLaTeX.com\" height=\"18\" width=\"157\" style=\"vertical-align: -4px;\"\/> as for the centered difference.<\/p>\n<h2>Discretizing the Schr\u00f6dinger equation<\/h2>\n<p>We are now ready to discretize the Hamiltonian of the one dimensional Schr\u00f6dinger equation<\/p>\n<p class=\"ql-center-displayed-equation\" style=\"line-height: 44px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-a26d3ce344d8035e01c632cf52752fb1_l3.png\" height=\"44\" width=\"275\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#091; &#72;&#92;&#80;&#115;&#105;&#40;&#120;&#41;&#32;&#61;&#32;&#92;&#108;&#101;&#102;&#116;&#40;&#92;&#102;&#114;&#97;&#99;&#123;&#45;&#92;&#104;&#98;&#97;&#114;&#94;&#50;&#125;&#123;&#50;&#109;&#125;&#92;&#102;&#114;&#97;&#99;&#123;&#100;&#94;&#50;&#125;&#123;&#100;&#120;&#94;&#50;&#125;&#32;&#43;&#32;&#86;&#40;&#120;&#41;&#92;&#114;&#105;&#103;&#104;&#116;&#41;&#92;&#80;&#115;&#105;&#40;&#120;&#41;&#46; &#92;&#093;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>\n<p>Noting that when <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-5d850acc408f2b161c248a9c23701de8_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#80;&#115;&#105;&#40;&#120;&#41;\" title=\"Rendered by QuickLaTeX.com\" height=\"18\" width=\"36\" style=\"vertical-align: -4px;\"\/> is defined on a discrete lattice, the potential <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-6835e5d0fcceb1166b142b823ef3728e_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#86;&#40;&#120;&#41;\" title=\"Rendered by QuickLaTeX.com\" height=\"18\" width=\"37\" style=\"vertical-align: -4px;\"\/> becomes a diagonal matrix <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-29f854c8c17e600efbed19867aea7565_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#86;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"14\" style=\"vertical-align: 0px;\"\/> with <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-aea0a4afb29a6d2ceb34cee8d4b8290e_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#86;&#40;&#120;&#95;&#110;&#41;\" title=\"Rendered by QuickLaTeX.com\" height=\"18\" width=\"46\" style=\"vertical-align: -4px;\"\/> along the diagonal. Using this together with the discretized approximation of the second derivative derived above, the discretized Hamiltonian becomes<\/p>\n<p class=\"ql-center-displayed-equation\" style=\"line-height: 39px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-7537870d15efeaed400317781715d26b_l3.png\" height=\"39\" width=\"157\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#091; &#72;&#95;&#123;&#68;&#125;&#32;&#61;&#32;&#92;&#102;&#114;&#97;&#99;&#123;&#45;&#92;&#104;&#98;&#97;&#114;&#94;&#50;&#125;&#123;&#50;&#109;&#125;&#68;&#94;&#123;&#40;&#50;&#41;&#125;&#32;&#43;&#32;&#86;&#46; &#92;&#093;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>\n<h2>Second quantized formulation<\/h2>\n<p>While the equation above is a matrix equation, TBTK is intended for Hamiltonians on second quantization form, which for single particle physics means<\/p>\n<p class=\"ql-center-displayed-equation\" style=\"line-height: 42px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-565fa947c6d4c41105c9d438ab3a7ff7_l3.png\" height=\"42\" width=\"132\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#091; &#72;&#95;&#123;&#115;&#113;&#125;&#32;&#61;&#32;&#92;&#115;&#117;&#109;&#95;&#123;&#92;&#109;&#97;&#116;&#104;&#98;&#102;&#123;&#105;&#125;&#92;&#109;&#97;&#116;&#104;&#98;&#102;&#123;&#106;&#125;&#125;&#97;&#95;&#123;&#92;&#109;&#97;&#116;&#104;&#98;&#102;&#123;&#105;&#125;&#92;&#109;&#97;&#116;&#104;&#98;&#102;&#123;&#106;&#125;&#125;&#99;&#95;&#123;&#92;&#109;&#97;&#116;&#104;&#98;&#102;&#123;&#105;&#125;&#125;&#94;&#123;&#92;&#100;&#97;&#103;&#103;&#101;&#114;&#125;&#99;&#95;&#123;&#92;&#109;&#97;&#116;&#104;&#98;&#102;&#123;&#106;&#125;&#125;&#46; &#92;&#093;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>\n<p>However, as long as we are concerned with single particle physics, this is really nothing else than a different notation for a matrix with matrix elements <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-8e7bef616b76300c7528d5be3f29239f_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#97;&#95;&#123;&#92;&#109;&#97;&#116;&#104;&#98;&#102;&#123;&#105;&#125;&#92;&#109;&#97;&#116;&#104;&#98;&#102;&#123;&#106;&#125;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"14\" width=\"17\" style=\"vertical-align: -6px;\"\/>. That is, <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-1b8efe2424cfdcf9d67a6ecabb69d4aa_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#109;&#97;&#116;&#104;&#98;&#102;&#123;&#105;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"6\" style=\"vertical-align: 0px;\"\/> and <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-fd56b3f435faf309813ad9a4a25223ef_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#109;&#97;&#116;&#104;&#98;&#102;&#123;&#106;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"6\" style=\"vertical-align: -3px;\"\/> can be understood as generalized row and column indices, respectively.<\/p>\n<p>To specify a model corresponding to the finite difference equation above in TBTK, all we need to do now is to think of HoppingAmplitude(value, i, j) as another notation for MatrixElement(value, row, column). We can, therefore, read of the matrix elements of our operators <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-90b09868272a4404c679b2569ba6322c_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#45;&#40;&#92;&#104;&#98;&#97;&#114;&#94;&#50;&#47;&#50;&#109;&#41;&#68;&#94;&#123;&#40;&#50;&#41;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"22\" width=\"108\" style=\"vertical-align: -5px;\"\/> and <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-29f854c8c17e600efbed19867aea7565_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#86;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"14\" style=\"vertical-align: 0px;\"\/> directly and feed these to our model. For the diagonal terms, this means <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-96ccb5d41505838f20bea41a85bdd077_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#104;&#98;&#97;&#114;&#94;&#50;&#47;&#109;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#94;&#50;&#32;&#43;&#32;&#86;&#40;&#120;&#95;&#110;&#41;\" title=\"Rendered by QuickLaTeX.com\" height=\"20\" width=\"142\" style=\"vertical-align: -5px;\"\/>, while for the first off-diagonals we find <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-8ddddc86b8f0634f9036f27bcab50563_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#45;&#92;&#104;&#98;&#97;&#114;&#94;&#50;&#47;&#50;&#109;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#94;&#50;\" title=\"Rendered by QuickLaTeX.com\" height=\"20\" width=\"96\" style=\"vertical-align: -5px;\"\/>. Separating the two diagonal terms, we can implement the model specification in TBTK as follows.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\ndouble t = hbar*hbar\/(2*m*dx*dx);\r\n\r\nModel model;\r\nfor(int x = 0; x &lt; SIZE_X; x++){\r\n    \/\/Add the second derivative.\r\n    model &lt;&lt; HoppingAmplitude(2*t, {x}, {x});\r\n    if(x + 1 &lt; SIZE_X){\r\n        model &lt;&lt; HoppingAmplitude(\r\n            -t,\r\n            {x + 1},\r\n            {x}\r\n        ) + HC;\r\n    }\r\n\r\n    \/\/Add the potential.\r\n    model &lt;&lt; V&#x5B;x];\r\n}\r\nmodel.construct();\r\n<\/pre>\n<p>Here the variables hbar, m, dx, and SIZE_X, as well as the array V containing the potential is assumed to already have been defined. Also note that only the HoppingAmplitude corresponding to the lower off-diagonal terms is written out explicitly, while the upper off-diagonal terms are included because of &#8220;+ HC&#8221; at the end of line 12.<\/p>\n<h2>Extention to multiple dimensions<\/h2>\n<p>The construction of a multi-dimensional finite difference equation is similar to the procedure described above. However, the function that is being differentiated now depends on several variables that together define a multi-dimensional discrete lattice after discretization. A traditional matrix formulation requires these lattice points to be labeled by a linear index to know which lattice point corresponds to which position in the vectorization of the function, and there are several ways of doing so. The exact form of the derivative operators will, therefore, depend on the convention chosen.<\/p>\n<p>This is a situation in which TBTK shows significant strength since it provides this mapping automatically and allows for the specification of the model using the more natural physical indices. Taking two dimensions as an example, where the physical index is {x, y}, it is simple to extend the one-dimensional case above as follows.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\ndouble t_x = hbar*hbar\/(2*m*dx*dx);\r\ndouble t_y = hbar*hbar\/(2*m*dy*dy);\r\n\r\nModel model;\r\nfor(int x = 0; x &lt; SIZE_X; x++){\r\n    for(int y = 0; y &lt; SIZE_Y; y++){\r\n        \/\/Add the second derivative,\r\n        \/\/x-direction.\r\n        model &lt;&lt; HoppingAmplitude(\r\n            2*t_x,\r\n            {x, y},\r\n            {x, y}\r\n        );\r\n        if(x + 1 &lt; SIZE_X){\r\n            model &lt;&lt; HoppingAmplitude(\r\n                -t_x,\r\n                {x + 1, y},\r\n                {x,     y}\r\n            ) + HC;\r\n        }\r\n\r\n        \/\/Add the second derivative,\r\n        \/\/y-direction.\r\n        model &lt;&lt; HoppingAmplitude(\r\n            2*t_y,\r\n            {x, y},\r\n            {x, y}\r\n        );\r\n        if(y + 1 &lt; SIZE_Y){\r\n            model &lt;&lt; HoppingAmplitude(\r\n                -t_y,\r\n                {x, y + 1},\r\n                {x, y}\r\n            ) + HC;\r\n        }\r\n\r\n        \/\/Add the potential.\r\n        model &lt;&lt; V&#x5B;x]&#x5B;y];\r\n    }\r\n}\r\nmodel.construct();\r\n<\/pre>\n<p>The code is almost identical to the code for the one-dimensional case, and for clarity, we have here allowed for different step lengths along the x and y directions.<\/p>\n<h2>Final words<\/h2>\n<p>Finite differences is the most straight forward way to convert a differential equation into a form suitable for numerical calculations. We have only scratched on the surface here by for example only focusing on the boundary conditions <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/second-tech.com\/wordpress\/wp-content\/ql-cache\/quicklatex.com-2155cb3994c8e45b3e4fef7b22128d9d_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#102;&#40;&#120;&#95;&#123;&#45;&#49;&#125;&#41;&#32;&#61;&#32;&#102;&#40;&#120;&#95;&#123;&#78;&#125;&#41;&#32;&#61;&#32;&#48;\" title=\"Rendered by QuickLaTeX.com\" height=\"18\" width=\"157\" style=\"vertical-align: -4px;\"\/>. We have also left out higher-order approximations and non-uniform grids. However, we have covered enough material to provide a full understanding of the essential nature of finite differences, as well as demonstrated how TBTK makes it particularly simple to work with these also in higher dimensions.<\/p>\n<p>Since it is so simple to set up finite difference schemes in general using TBTK, it can be of interest beyond the application to quantum mechanics. If you have an interested in finite difference schemes more generally and want to know more about how TBTK can be used to simplify such calculations, then see for example how to set up <a href=\"http:\/\/second-tech.com\/wordpress\/index.php\/2018\/11\/01\/creating-models-with-complex-geometries-using-an-indexfilter-in-tbtk\/\">complex geometries<\/a> and how to <a href=\"http:\/\/second-tech.com\/wordpress\/index.php\/2018\/11\/04\/retrieving-the-hamiltonian-from-the-model-in-tbtk\/\">extract the matrix formulation<\/a> of the problem from the model.<\/p>\n<p>In this post, we have only provided two code fragments to demonstrate the principle. For examples of the application of finite differences to solve concrete quantum mechanical problems, see for example:<\/p>\n<p><a href=\"http:\/\/second-tech.com\/wordpress\/index.php\/2018\/10\/23\/using-tbtk-to-calculate-the-density-of-states-dos-of-a-1d-2d-and-3d-square-lattice\/\">Using TBTK to calculate the density of states (DOS) of a 1D, 2D, and 3D square lattice<\/a><\/p>\n<p><a href=\"http:\/\/second-tech.com\/wordpress\/index.php\/2018\/10\/27\/direct-access-to-wave-function-amplitudes-and-eigenvalues-in-tbtk\/\">Direct access to wave function amplitudes and eigenvalues in TBTK<\/a><\/p>\n<p><a href=\"http:\/\/second-tech.com\/wordpress\/index.php\/2018\/11\/01\/creating-models-with-complex-geometries-using-an-indexfilter-in-tbtk\/\">Creating Models with complex geometries using an IndexFilter in TBTK<\/a><\/p>\n<p><a href=\"http:\/\/second-tech.com\/wordpress\/index.php\/2018\/11\/07\/dynamically-adjustable-hoppingamplitudes-using-callback-functions-in-tbtk\/\">Dynamically adjustable HoppingAmplitudes using callback functions in TBTK<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Most recent TBTK release at the time of writing: v1.0.3 Single-particle quantum mechanics is usually formulated using a differential equation such as the Schr\u00f6dinger equation. The simplest way to solve this numerically is through the use of finite differences. While TBTK is designed for discrete problems formulated on second quantized form, this includes the possibility &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/second-tech.com\/wordpress\/index.php\/2018\/11\/10\/finite-differences-and-second-quantization\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Finite differences and second quantization&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/second-tech.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/1300"}],"collection":[{"href":"http:\/\/second-tech.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/second-tech.com\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/second-tech.com\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/second-tech.com\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=1300"}],"version-history":[{"count":175,"href":"http:\/\/second-tech.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/1300\/revisions"}],"predecessor-version":[{"id":1680,"href":"http:\/\/second-tech.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/1300\/revisions\/1680"}],"wp:attachment":[{"href":"http:\/\/second-tech.com\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=1300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/second-tech.com\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=1300"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/second-tech.com\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=1300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}