Final: Do task 4.4, draft task 4.5

This commit is contained in:
2022-04-04 11:17:43 +02:00
parent d2df71f973
commit 4de898ff78

View File

@ -1530,7 +1530,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 19,
"metadata": {
"deletable": false,
"nbgrader": {
@ -1548,8 +1548,21 @@
"outputs": [],
"source": [
"def getU_CN(tau, H):\n",
" # YOUR CODE HERE\n",
" raise NotImplementedError()\n",
" \"\"\"\n",
" Calculates the time-propagation matrix for time-step tau using\n",
" the Crank-Nicolson algorithm.\n",
" \n",
" Args:\n",
" tau: time-step numeric to calculate the time-propagation matrix at\n",
" H: n by n array representing the hamiltonian matrix\n",
"\n",
" Returns:\n",
" The time-propagation matrix U(tau).\n",
" \"\"\"\n",
" \n",
" n = len(H)\n",
" \n",
" return (np.eye(n) - 1j*tau*H/2)@np.linalg.inv(np.eye(n) + 1j*tau*H/2)\n",
"\n",
"# Yann notes that the definition of $U_{CN}(\\tau)$ here is a little\n",
"# different from what Malte used on the slides. He recommends using\n",
@ -1602,7 +1615,80 @@
}
},
"source": [
"YOUR ANSWER HERE"
"% BEGIN NOTES %\n",
"Koen: vergeet niet -1j*tau mee te nemen.\n",
"\n",
"H = H_1 + H_2\n",
"H_1 = [[0,t],[t,0]] bla bla blok\n",
"H_2 \n",
"\n",
"verschil n even en n oneven?\n",
"\n",
"Zie slide 14 en omgeving in 08_Partial_Diff.\n",
"\n",
"Vergeet niet 1 op de diagonalon\n",
"% END NOTES %\n",
"\n",
"In the Trotter-Suzuki decomposition, we seek for block matrix forms for $\\mathbf{H_1}$ and $\\mathbf{H_2}$ such that their sum equals the original matrix $\\mathbf{H}$. The exponential is than done for each block instead of the whole matrix, which is a lot less complicated. Afterwards the result is combined such that\n",
"$$\n",
"e^{-i\\tau\\mathbf{H}} = e^{-i \\tau\\left( \\mathbf{H_1} + \\mathbf{H_2} \\right)} \\approx e^{-i\\tau\\mathbf{H_1}} \\cdot e^{-i\\tau\\mathbf{H_2}}\n",
"$$\n",
"\n",
"Here are the forms for the matrices. For $\\mathbf{H}$ an $n \\times n$ matrix, the form for $n$ odd is written down below. For $n$ even, the last row and column for both matrices can be omitted to see the shape.\n",
"\n",
"$$\n",
"\\mathbf{H_1} =\n",
"\\begin{pmatrix}\n",
"0 & t & & & & & & \\\\\n",
"t & 0 & & & & & & \\\\\n",
" & & 0 & t & & & & \\\\\n",
" & & t & 0 & & & & \\\\\n",
" & & & & \\ddots & & & \\\\\n",
" & & & & & 0 & t & \\\\\n",
" & & & & & t & 0 & \\\\\n",
" & & & & & & & 0\n",
"\\end{pmatrix}\n",
"\\qquad\n",
"\\mathbf{H_2} =\n",
"\\begin{pmatrix}\n",
"0 & & & & & & & \\\\\n",
" & 0 & t & & & & & \\\\\n",
" & t & 0 & & & & & \\\\\n",
" & & & 0 & t & & & \\\\\n",
" & & & t & 0 & & & \\\\\n",
" & & & & & \\ddots & & \\\\\n",
" & & & & & & 0 & t\\\\\n",
" & & & & & & t & 0\n",
"\\end{pmatrix}\n",
"$$\n",
"\n",
"For the exponents, we find the following for $n$ odd, again with the remark that the result for $n$ even can be reached by omitting the last row and column for both matrices and calculating the exponents for them.\n",
"\\begin{align}\n",
"\\exp{\\mathbf{H_1}} &=\n",
"\\begin{pmatrix}\n",
"\\exp{\\begin{pmatrix}0 & -i\\tau{}t \\\\ -i\\tau{}t & 0\\end{pmatrix}} & & & &\\\\\n",
" & \\exp{\\begin{pmatrix}0 & -i\\tau{}t \\\\ -i\\tau{}t & 0\\end{pmatrix}} & & &\\\\\n",
" & & \\ddots & &\\\\\n",
" & & & \\exp{\\begin{pmatrix}0 & -i\\tau{}t \\\\ -i\\tau{}t & 0\\end{pmatrix}} &\\\\\n",
" & & & & \\exp{0}\n",
"\\end{pmatrix}\n",
"\\\\\n",
"\\exp{\\mathbf{H_2}} &=\n",
"\\begin{pmatrix}\n",
"\\exp{0} & & & &\\\\\n",
" & \\exp{\\begin{pmatrix}0 & -i\\tau{}t \\\\ -i\\tau{}t & 0\\end{pmatrix}} & & &\\\\\n",
" & & \\exp{\\begin{pmatrix}0 & -i\\tau{}t \\\\ -i\\tau{}t & 0\\end{pmatrix}} & &\\\\\n",
" & & & \\ddots &\\\\\n",
" & & & & \\exp{\\begin{pmatrix}0 & -i\\tau{}t \\\\ -i\\tau{}t & 0\\end{pmatrix}}\\\\\n",
" & & & &\n",
"\\end{pmatrix}\n",
"\\end{align}\n",
"\n",
"As $\\exp{0} = 1$, we just calculate\n",
"$$\n",
"\\exp{\\begin{pmatrix}0 & -i\\tau{}t \\\\ -i\\tau{}t & 0\\end{pmatrix}}\n",
"= \\begin{pmatrix}\\cos{\\tau{}t} & -i\\sin{\\tau{}t} \\\\ -i\\sin{\\tau{}t} & \\cos{\\tau{}t}\\end{pmatrix}.\n",
"$$\n"
]
},
{
@ -1625,6 +1711,26 @@
"outputs": [],
"source": [
"def getU_TZ(tau, H):\n",
" # TODO: Add docstring.\n",
" \n",
" # First we calculate the exponent of the block.\n",
" exp_block = np.array([\n",
" [ np.cos(tau*t), -1j*np.sin(tau*t)],\n",
" [-1j*np.sin(tau*t), np.cos(tau*t)]\n",
" ])\n",
" \n",
" # Now we use the block to calculate the exponent of matrices\n",
" # H_1 and H_2.\n",
" n = len(H)\n",
" exp_H_1 = np.block([\n",
" [1, 0],\n",
" [0, np.kron(np.eye(n//2, dtype=int), exp_block)]\n",
" ])\n",
" exp_H_2 = np.block([\n",
" [1, 0],\n",
" [0, np.kron(np.eye(n//2, dtype=int), exp_block)]\n",
" ])\n",
" \n",
" # YOUR CODE HERE\n",
" raise NotImplementedError()\n",
"\n",