11: Add some ideas to task 4, fix minor typos

This commit is contained in:
2022-03-18 10:29:54 +01:00
parent 1d7dec786c
commit 6f70d0d539

View File

@ -195,7 +195,7 @@
" the approximations ℏ = 1, 𝑚 = 0.5.\n",
" \n",
" Args:\n",
" x: array of evenly spaced space value vectors x\n",
" x: array of evenly spaced space values x\n",
" V: function that takes in a location x and returns a scalar potential value\n",
"\n",
" Returns:\n",
@ -456,7 +456,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {
"deletable": false,
"nbgrader": {
@ -471,10 +471,54 @@
"task": false
}
},
"outputs": [],
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (1568846030.py, line 24)",
"output_type": "error",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"/tmp/ipykernel_2225683/1568846030.py\"\u001b[0;36m, line \u001b[0;32m24\u001b[0m\n\u001b[0;31m α =\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
]
}
],
"source": [
"def SEQDyn(x, t, V, f):\n",
" # YOUR CODE HERE"
" \"\"\"\n",
" Numerically solves the time-dependent Schrödinger equation over\n",
" the gives input parameters, in a potential given by V, using\n",
" the approximations ℏ = 1, 𝑚 = 0.5, using the Crank-Nicolson approach\n",
" \n",
" Args:\n",
" x: array of evenly spaced space values x\n",
" t: array of evenly spaced time values t\n",
" V: function that takes a location x and returns a scalar potential value\n",
" f: function that takes a location x and returns initial values to w for\n",
" the Crank-Nicolson approach\n",
"\n",
" Returns:\n",
" A tuple of eigenfunctions \\Psi of the time-dependent SE.\n",
" \"\"\"\n",
" \n",
" n = len(x)\n",
" h = x[1] - x[0]\n",
" m = len(t)\n",
" k = t[1] - t[0]\n",
" \n",
" # Setup the Crank-Nicholson parameters\n",
" α =\n",
" λ1 = α**2*k/h**2\n",
" λ2 = 1\n",
" \n",
" A = -λ1/2*( np.eye(m - 2, m - 2, -1) + np.eye(m - 2, m - 2, 1) ) - (1 + λ1 + λ2*V)*np.eye(m - 2)\n",
" B = +λ1/2*( np.eye(m - 2, m - 2, -1) + np.eye(m - 2, m - 2, 1) ) - (1 + λ1 + λ2*V)*np.eye(m - 2)\n",
"\n",
" # TODO: Finish SEQDyn: implement algorithm, return the right things.\n",
"\n",
"\n",
"V = lambda x: 0.25*x**2\n",
"f = lambda x: np.exp(-x**2)/2.5\n",
"x = np.linspace(-5, 5, 100)\n",
"t = np.linspace(0, 50, 1000)"
]
},
{
@ -606,7 +650,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},