Fetch week 6
This commit is contained in:
463
Week 6/10 Hyperbolic PDEs.ipynb
Normal file
463
Week 6/10 Hyperbolic PDEs.ipynb
Normal file
@ -0,0 +1,463 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
"editable": false,
|
||||
"nbgrader": {
|
||||
"cell_type": "markdown",
|
||||
"checksum": "4ec40081b048ce2f34f3f4fedbb0be10",
|
||||
"grade": false,
|
||||
"grade_id": "cell-98f724ece1aacb67",
|
||||
"locked": true,
|
||||
"schema_version": 3,
|
||||
"solution": false,
|
||||
"task": false
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"# CDS: Numerical Methods Assignments\n",
|
||||
"\n",
|
||||
"- See lecture notes and documentation on Brightspace for Python and Jupyter basics. If you are stuck, try to google or get in touch via Discord.\n",
|
||||
"\n",
|
||||
"- Solutions must be submitted via the Jupyter Hub.\n",
|
||||
"\n",
|
||||
"- Make sure you fill in any place that says `YOUR CODE HERE` or \"YOUR ANSWER HERE\".\n",
|
||||
"\n",
|
||||
"## Submission\n",
|
||||
"\n",
|
||||
"1. Name all team members in the the cell below\n",
|
||||
"2. make sure everything runs as expected\n",
|
||||
"3. **restart the kernel** (in the menubar, select Kernel$\\rightarrow$Restart)\n",
|
||||
"4. **run all cells** (in the menubar, select Cell$\\rightarrow$Run All)\n",
|
||||
"5. Check all outputs (Out[\\*]) for errors and **resolve them if necessary**\n",
|
||||
"6. submit your solutions **in time (before the deadline)**"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "raw",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"team_members = \"\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
"editable": false,
|
||||
"nbgrader": {
|
||||
"cell_type": "markdown",
|
||||
"checksum": "62fbcf7aaa9e165abd27319c5bd35555",
|
||||
"grade": false,
|
||||
"grade_id": "cell-e9dc85dd9ad77a5e",
|
||||
"locked": true,
|
||||
"schema_version": 3,
|
||||
"solution": false,
|
||||
"task": false
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"## Dynamic Behavior from Hyperbolic PDEs\n",
|
||||
"\n",
|
||||
"In the following you will derive and implement finite-difference methods to study generalized hyperbolic partial differential equations."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
"nbgrader": {
|
||||
"cell_type": "code",
|
||||
"checksum": "910692c2f4b93f251a3a128caf2b0c37",
|
||||
"grade": true,
|
||||
"grade_id": "cell-acb87410eaef9fe1",
|
||||
"locked": false,
|
||||
"points": 0,
|
||||
"schema_version": 3,
|
||||
"solution": true,
|
||||
"task": false
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Import packages here ...\n",
|
||||
"\n",
|
||||
"# YOUR CODE HERE\n",
|
||||
"raise NotImplementedError()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
"editable": false,
|
||||
"nbgrader": {
|
||||
"cell_type": "markdown",
|
||||
"checksum": "7238a56701aaf868838ffdb706f5eb8b",
|
||||
"grade": false,
|
||||
"grade_id": "cell-a27c54a734bf2232",
|
||||
"locked": true,
|
||||
"schema_version": 3,
|
||||
"solution": false,
|
||||
"task": false
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"### Task 1: finite-difference hyperbolic PDE solver\n",
|
||||
"\n",
|
||||
"Our aim is to implement a Python function to find the solution of the following PDE:\n",
|
||||
"\n",
|
||||
"\\begin{align*}\n",
|
||||
" \\frac{\\partial^2}{\\partial t^2} u(x,t)\n",
|
||||
" - \\alpha^2 \\frac{\\partial^2}{\\partial x^2} u(x,t) = 0,\n",
|
||||
" \\qquad\n",
|
||||
" 0 \\leq x \\leq l,\n",
|
||||
" \\qquad\n",
|
||||
" 0 \\leq t\n",
|
||||
"\\end{align*}\n",
|
||||
"\n",
|
||||
"with the boundary conditions\n",
|
||||
"\n",
|
||||
"\\begin{align*}\n",
|
||||
" u(0,t) = u(l,t) &= 0, \n",
|
||||
" &&\\text{for } t > 0 \\\\\n",
|
||||
" u(x,0) &= f(x) \\\\\n",
|
||||
" \\frac{\\partial}{\\partial t} u(x,0) &= g(x)\n",
|
||||
" &&\\text{for } 0 \\leq x \\leq l.\n",
|
||||
"\\end{align*}\n",
|
||||
" \n",
|
||||
"By approximating the partial derivatives with finite differences we can recast the problem into the following form\n",
|
||||
"\t\t\n",
|
||||
"\\begin{align*}\n",
|
||||
" \\vec{w}_{j+1} = \\mathbf{A} \\vec{w}_{j}\n",
|
||||
" - \\vec{w}_{j-1}.\n",
|
||||
"\\end{align*}\n",
|
||||
"\n",
|
||||
"Here $\\vec{w}_j$ is a vector of length $m$ in the discretized spatial coordinate $x_i$ at time step $t_j$. The spatial coordinates are defined as $x_i = i h$, where $i=0,1,\\dots,m-1$ and $h = l/(m-1)$. The time steps are defined as $t_j = j k$, where $j = 0, 1, \\dots, n-1$.\n",
|
||||
"\n",
|
||||
"The tri-diagonal matrix $\\mathbf{A}$ has size $(m-2)\\times(m-2)$ and is defined by\n",
|
||||
"\n",
|
||||
"\\begin{align*}\n",
|
||||
" \\mathbf{A} =\n",
|
||||
" \\left( \\begin{array}{cccc}\n",
|
||||
" 2(1-\\lambda^2) & \\lambda^2 & & 0\\\\\n",
|
||||
" \\lambda^2 & \\ddots & \\ddots & \\\\\n",
|
||||
" & \\ddots & \\ddots & \\lambda^2 \\\\\n",
|
||||
" 0 & & \\lambda^2 & 2(1-\\lambda^2) \n",
|
||||
" \\end{array} \\right),\n",
|
||||
"\\end{align*}\n",
|
||||
" \n",
|
||||
"where $\\lambda = \\alpha k / h$. This $(m-2)\\times(m-2)$ structure accounts for the first set of boundary conditions. Note that the product $\\mathbf{A} \\vec{w}_{j}$ is thus only performed over the $m-2$ subset, i.e. $i=1,2,\\dots,m-2$. The other boundary conditions are accounted for by initializing the first two time steps with\n",
|
||||
"\n",
|
||||
"\\begin{align*}\n",
|
||||
" w_{i,j=0} &= f(x_i) \\\\\n",
|
||||
" w_{i,j=1} &= (1-\\lambda^2) f(x_i)\n",
|
||||
" + \\frac{\\lambda^2}{2} f(x_{i+1})\n",
|
||||
" + \\frac{\\lambda^2}{2} f(x_{i-1})\n",
|
||||
" + kg(x_i).\n",
|
||||
"\\end{align*}\n",
|
||||
" \n",
|
||||
"Implement a Python function of the form $\\text{pdeHyperbolic(a, x, t, f, g)}$, where $\\text{a}$ represents the PDE parameter $\\alpha$, $\\text{x}$ and $\\text{t}$ are the discretized spatial and time grids, and $\\text{f}$ and $\\text{g}$ are the functions defining the boundary conditions. This function should return a two-dimensional array $\\text{w[:,:]}$, which stores the spatial vector $\\vec{w}_j$ at each time coordinate $t_j$."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
"nbgrader": {
|
||||
"cell_type": "code",
|
||||
"checksum": "95d463713a216d57cbf814a0f40a482d",
|
||||
"grade": true,
|
||||
"grade_id": "cell-1f9655333f2dc3cb",
|
||||
"locked": false,
|
||||
"points": 3,
|
||||
"schema_version": 3,
|
||||
"solution": true,
|
||||
"task": false
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def pdeHyperbolic(a, x, t, f, g):\n",
|
||||
" # YOUR CODE HERE\n",
|
||||
" raise NotImplementedError()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
"editable": false,
|
||||
"nbgrader": {
|
||||
"cell_type": "markdown",
|
||||
"checksum": "d5ee65aba16eef98296a6a66af3c0888",
|
||||
"grade": false,
|
||||
"grade_id": "cell-047f2dfab5489a88",
|
||||
"locked": true,
|
||||
"schema_version": 3,
|
||||
"solution": false,
|
||||
"task": false
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"### Task 2 \n",
|
||||
"\n",
|
||||
"Use your implementation to solve the following problems. Compare in the first problem your numerical solution to the analytic one and use it to debug your code.\n",
|
||||
"\n",
|
||||
"#### Problem 1:\n",
|
||||
"\\begin{align*}\n",
|
||||
" \\frac{\\partial^2}{\\partial t^2} u(x,t)\n",
|
||||
" - \\frac{\\partial^2}{\\partial x^2} u(x,t) &= 0,\n",
|
||||
" &&\\text{for }0 \\leq x \\leq 1 \\text{ and } 0 \\leq t \\leq 1\\\\\n",
|
||||
" u(0,t) = u(l,t) &= 0, \n",
|
||||
" &&\\text{for } t > 0 \\\\\n",
|
||||
" u(x,0) &= \\operatorname{sin}\\left(2 \\pi x \\right), \\\\\n",
|
||||
" \\frac{\\partial}{\\partial t} u(x,0) &= 2 \\pi \\operatorname{sin}\\left(2 \\pi x \\right)\n",
|
||||
" &&\\text{for } 0 \\leq x \\leq 1.\n",
|
||||
"\\end{align*}\n",
|
||||
"\n",
|
||||
"Compare your numerical solution to the analytic one and use it to debug your code. The corresponding analytic solution is\n",
|
||||
"\n",
|
||||
"\\begin{equation}\n",
|
||||
" u(x,t) = \\operatorname{sin}(2 \\pi x) (\\operatorname{cos}(2 \\pi t) + \\operatorname{sin}(2 \\pi t)).\n",
|
||||
"\\end{equation}\n",
|
||||
"\n",
|
||||
"Then write a unit test for your function based on this problem."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
"nbgrader": {
|
||||
"cell_type": "code",
|
||||
"checksum": "17a4067a37c5edfaffd6ebffa47942d6",
|
||||
"grade": true,
|
||||
"grade_id": "cell-8b8cb282dfe95a03",
|
||||
"locked": false,
|
||||
"points": 0,
|
||||
"schema_version": 3,
|
||||
"solution": true,
|
||||
"task": false
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Do your own testing here ...\n",
|
||||
"\n",
|
||||
"# YOUR CODE HERE\n",
|
||||
"raise NotImplementedError()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
"nbgrader": {
|
||||
"cell_type": "code",
|
||||
"checksum": "fbb85c41f7de70517abcdc482a875fd5",
|
||||
"grade": true,
|
||||
"grade_id": "cell-e83b24067743e433",
|
||||
"locked": false,
|
||||
"points": 3,
|
||||
"schema_version": 3,
|
||||
"solution": true,
|
||||
"task": false
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def test_pdeHyperbolic():\n",
|
||||
" # YOUR CODE HERE\n",
|
||||
" raise NotImplementedError()\n",
|
||||
" \n",
|
||||
"test_pdeHyperbolic()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
"editable": false,
|
||||
"nbgrader": {
|
||||
"cell_type": "markdown",
|
||||
"checksum": "42880f6025ac92dc08f1c44a5bbf4312",
|
||||
"grade": false,
|
||||
"grade_id": "cell-99399435c164c96d",
|
||||
"locked": true,
|
||||
"schema_version": 3,
|
||||
"solution": false,
|
||||
"task": false
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"#### Problem 2:\n",
|
||||
"\n",
|
||||
"\\begin{align*}\n",
|
||||
" \\frac{\\partial^2}{\\partial t^2} u(x,t)\n",
|
||||
" - \\frac{\\partial^2}{\\partial x^2} u(x,t) &= 0,\n",
|
||||
" &&\\text{for }0 \\leq x \\leq 1 \\text{ and } 0 \\leq t \\leq 2\\\\\n",
|
||||
" u(0,t) = u(l,t) &= 0, \n",
|
||||
" &&\\text{for } t > 0 \\\\\n",
|
||||
" u(x,0) &= \\left\\{ \\begin{array}{cc} +1 & \\text{for } x<0.5 \\\\ -1 & \\text{for } x \\geq 0.5 \\end{array} \\right., \\\\\n",
|
||||
" \\frac{\\partial}{\\partial t} u(x,0) &= 0\n",
|
||||
" &&\\text{for } 0 \\leq x \\leq 1.\n",
|
||||
"\\end{align*}\n",
|
||||
"\n",
|
||||
"Use $m=200$ and $n=400$ to discretize the spatial and time grids, respectively."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
"nbgrader": {
|
||||
"cell_type": "code",
|
||||
"checksum": "1b6e620f32a96a23c736b827e282bc6b",
|
||||
"grade": true,
|
||||
"grade_id": "cell-ea865d2efbc574d6",
|
||||
"locked": false,
|
||||
"points": 2,
|
||||
"schema_version": 3,
|
||||
"solution": true,
|
||||
"task": false
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# YOUR CODE HERE\n",
|
||||
"raise NotImplementedError()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
"editable": false,
|
||||
"nbgrader": {
|
||||
"cell_type": "markdown",
|
||||
"checksum": "3bb27614fe36d18302f4ace6442c67d9",
|
||||
"grade": false,
|
||||
"grade_id": "cell-a783908a0db32a24",
|
||||
"locked": true,
|
||||
"schema_version": 3,
|
||||
"solution": false,
|
||||
"task": false
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"### Task 3\n",
|
||||
"\n",
|
||||
"Animate your solutions! To this end you can use the following code:\n",
|
||||
"\n",
|
||||
"```python\n",
|
||||
"\n",
|
||||
"# use matplotlib's animation package\n",
|
||||
"import matplotlib.pylab as plt\n",
|
||||
"import matplotlib\n",
|
||||
"import matplotlib.animation as animation\n",
|
||||
"# set the animation style to \"jshtml\" (for the use in Jupyter)\n",
|
||||
"matplotlib.rcParams['animation.html'] = 'jshtml'\n",
|
||||
"\n",
|
||||
"# create a figure for the animation\n",
|
||||
"fig = plt.figure()\n",
|
||||
"plt.grid(True)\n",
|
||||
"plt.xlim( ... ) # fix x limits\n",
|
||||
"plt.ylim( ... ) # fix y limits\n",
|
||||
"\n",
|
||||
"# Create an empty plot object and prevent its showing (we will fill it each frame)\n",
|
||||
"myPlot, = plt.plot([0], [0])\n",
|
||||
"plt.close()\n",
|
||||
"\n",
|
||||
"# This function is called each frame to generate the animation (f is the frame number)\n",
|
||||
"def animate(f): \n",
|
||||
" myPlot.set_data( ... ) # update plot\n",
|
||||
"\n",
|
||||
"# Show the animation\n",
|
||||
"frames = np.arange(1, np.size(t)) # t is the time grid here\n",
|
||||
"myAnimation = animation.FuncAnimation(fig, animate, frames, interval = 20)\n",
|
||||
"myAnimation\n",
|
||||
"\n",
|
||||
"```"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
"nbgrader": {
|
||||
"cell_type": "code",
|
||||
"checksum": "5fa181b7e8df93bd0dd35613bc553701",
|
||||
"grade": true,
|
||||
"grade_id": "cell-0bd05d93759bd652",
|
||||
"locked": false,
|
||||
"points": 3,
|
||||
"schema_version": 3,
|
||||
"solution": true,
|
||||
"task": false
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Animate problem 1 here ...\n",
|
||||
"\n",
|
||||
"# YOUR CODE HERE\n",
|
||||
"raise NotImplementedError()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
"nbgrader": {
|
||||
"cell_type": "code",
|
||||
"checksum": "d4f93f8615bd3576e0248a27d5c1d664",
|
||||
"grade": true,
|
||||
"grade_id": "cell-43b3222743c428f5",
|
||||
"locked": false,
|
||||
"points": 0,
|
||||
"schema_version": 3,
|
||||
"solution": true,
|
||||
"task": false
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Animate problem 2 here ...\n",
|
||||
"\n",
|
||||
"# YOUR CODE HERE\n",
|
||||
"raise NotImplementedError()"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.10"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 4
|
||||
}
|
||||
@ -0,0 +1,489 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
"editable": false,
|
||||
"nbgrader": {
|
||||
"cell_type": "markdown",
|
||||
"checksum": "4ec40081b048ce2f34f3f4fedbb0be10",
|
||||
"grade": false,
|
||||
"grade_id": "cell-98f724ece1aacb67",
|
||||
"locked": true,
|
||||
"schema_version": 3,
|
||||
"solution": false,
|
||||
"task": false
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"# CDS: Numerical Methods Assignments\n",
|
||||
"\n",
|
||||
"- See lecture notes and documentation on Brightspace for Python and Jupyter basics. If you are stuck, try to google or get in touch via Discord.\n",
|
||||
"\n",
|
||||
"- Solutions must be submitted via the Jupyter Hub.\n",
|
||||
"\n",
|
||||
"- Make sure you fill in any place that says `YOUR CODE HERE` or \"YOUR ANSWER HERE\".\n",
|
||||
"\n",
|
||||
"## Submission\n",
|
||||
"\n",
|
||||
"1. Name all team members in the the cell below\n",
|
||||
"2. make sure everything runs as expected\n",
|
||||
"3. **restart the kernel** (in the menubar, select Kernel$\\rightarrow$Restart)\n",
|
||||
"4. **run all cells** (in the menubar, select Cell$\\rightarrow$Run All)\n",
|
||||
"5. Check all outputs (Out[\\*]) for errors and **resolve them if necessary**\n",
|
||||
"6. submit your solutions **in time (before the deadline)**"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "raw",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"team_members = \"\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
"editable": false,
|
||||
"nbgrader": {
|
||||
"cell_type": "markdown",
|
||||
"checksum": "d9d583d5ec524054533e809d7a5a63c1",
|
||||
"grade": false,
|
||||
"grade_id": "cell-b934b1147294eedc",
|
||||
"locked": true,
|
||||
"schema_version": 3,
|
||||
"solution": false,
|
||||
"task": false
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"## Parabolic PDEs: 1D Schrödinger Equation with Potential\n",
|
||||
"\n",
|
||||
"Here we aim to solve the 1D (parabolic) Schrödinger equation (SEQ) for a particle exposed to some potential $V(x)$\n",
|
||||
"\n",
|
||||
"\\begin{align*}\n",
|
||||
" i \\hbar \\frac{\\partial}{\\partial t} \\Psi(x, t) = \\frac{-\\hbar^2}{2m} \\frac{\\partial^2}{\\partial x^2} \\Psi(x, t) + V(x) \\Psi(x, t).\n",
|
||||
"\\end{align*}\n",
|
||||
" \n",
|
||||
"For simplicity we will set $\\hbar = 1$ and $m=0.5$ in the following. First you will analyze the stationary solutions of the SEQ for a given potential, using finite differences to approximate all involved derivatives. Then you will need to derive and apply the Crank-Nicolson approach for this PDE to study the dynamics of the SEQ."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
"nbgrader": {
|
||||
"cell_type": "code",
|
||||
"checksum": "f6fc23db350d1d6030229baabd0468a6",
|
||||
"grade": true,
|
||||
"grade_id": "cell-06b9782094f1febb",
|
||||
"locked": false,
|
||||
"points": 0,
|
||||
"schema_version": 3,
|
||||
"solution": true,
|
||||
"task": false
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Import packages here ...\n",
|
||||
"\n",
|
||||
"# YOUR CODE HERE\n",
|
||||
"raise NotImplementedError()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
"editable": false,
|
||||
"nbgrader": {
|
||||
"cell_type": "markdown",
|
||||
"checksum": "72c8dcfe08e449643bf3d6ba29e64d19",
|
||||
"grade": false,
|
||||
"grade_id": "cell-90c08182ba33b740",
|
||||
"locked": true,
|
||||
"schema_version": 3,
|
||||
"solution": false,
|
||||
"task": false
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"### Task 1\n",
|
||||
"\n",
|
||||
"The stationary SEQ\n",
|
||||
"\n",
|
||||
"\\begin{align*}\n",
|
||||
" H \\Psi(x) = \\frac{-\\hbar^2}{2m} \\frac{\\partial^2}{\\partial x^2} \\Psi(x) + V(x) \\Psi(x) = E \\Psi(x)\n",
|
||||
"\\end{align*}\n",
|
||||
"\n",
|
||||
"can be numerically studied by discretizing the spatial coordinate $x$ as $x_i = ih$ and approximating the second derivative with finite differences. This results in an eigenvalue problem of the form $H \\vec{\\Psi} = E \\vec{\\Psi}$, where $\\Psi$ is now a vector in the discretized positions $x_i$. By diagonalizing the matrix $H$ we simultaneously get both the eigenenergies $E_i$ and the corresponding eigenfunctions $\\vec{\\Psi}_i$. \n",
|
||||
"\n",
|
||||
"Derive the matrix representation of the Hamiltonian $H$ and write your final result in the cell below. (Double click on \"YOUR ANSWER HERE\" to open the cell, and ctrl+enter to compile.) \n",
|
||||
"\n",
|
||||
"Implement a simple Python function $\\text{SEQStat(x, V)}$ which takes the discretized grid $x_i$ and the potential $V(x)$ as arguments and which returns all eigenvalues $E$ and eigenfunctions $\\vec{\\Psi}$."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
"nbgrader": {
|
||||
"cell_type": "markdown",
|
||||
"checksum": "d005d991061648519880d606f6a8d768",
|
||||
"grade": true,
|
||||
"grade_id": "cell-65fbcafec53fde9d",
|
||||
"locked": false,
|
||||
"points": 1,
|
||||
"schema_version": 3,
|
||||
"solution": true,
|
||||
"task": false
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"YOUR ANSWER HERE"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
"nbgrader": {
|
||||
"cell_type": "code",
|
||||
"checksum": "b667798e88cf9611e65b3d37ed1a2f15",
|
||||
"grade": true,
|
||||
"grade_id": "cell-768b5f6973f4bf18",
|
||||
"locked": false,
|
||||
"points": 3,
|
||||
"schema_version": 3,
|
||||
"solution": true,
|
||||
"task": false
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def SEQStat(x, V):\n",
|
||||
" # YOUR CODE HERE\n",
|
||||
" raise NotImplementedError()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
"editable": false,
|
||||
"nbgrader": {
|
||||
"cell_type": "markdown",
|
||||
"checksum": "32c3d809b0a049d1a89854bf66fee90c",
|
||||
"grade": false,
|
||||
"grade_id": "cell-41993afec1730aac",
|
||||
"locked": true,
|
||||
"schema_version": 3,
|
||||
"solution": false,
|
||||
"task": false
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"### Task 2\n",
|
||||
"\n",
|
||||
"Use your function to calculate and plot the first few eigenfunctions for $V(x) = 0.25 x^2$. Add the potential to your plot. Use $-5 \\leq x \\leq +5$ discretized in $100$ steps."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
"nbgrader": {
|
||||
"cell_type": "code",
|
||||
"checksum": "8d73bb967269698e00749c2208366d7c",
|
||||
"grade": true,
|
||||
"grade_id": "cell-f39aca43ffd1c97a",
|
||||
"locked": false,
|
||||
"points": 3,
|
||||
"schema_version": 3,
|
||||
"solution": true,
|
||||
"task": false
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# YOUR CODE HERE\n",
|
||||
"raise NotImplementedError()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
"editable": false,
|
||||
"nbgrader": {
|
||||
"cell_type": "markdown",
|
||||
"checksum": "0d94afc9b832f5bc50c097e0f64281e1",
|
||||
"grade": false,
|
||||
"grade_id": "cell-d87f69447d0eb6dc",
|
||||
"locked": true,
|
||||
"schema_version": 3,
|
||||
"solution": false,
|
||||
"task": false
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"### Task 3\n",
|
||||
"\n",
|
||||
"Now we turn to the full dynamical problem, which can be numerically analyzed using the Crank-Nicolson approach, which averages over forward and backward scattering finite differences for the time derivative. Your task is to derive the corresponding formulas for the 1D SEQ from above, implement it, and apply it to study the time-dynamics for the 1D SEQ. Applying the Crank-Nicolson approach to the 1D SEQ from above results in an equation system of the form\n",
|
||||
"\n",
|
||||
"\\begin{align*}\n",
|
||||
" \\mathbf{A} \\vec{w}_{j+1} = \\mathbf{B} \\vec{w}_{j}\n",
|
||||
"\\end{align*}\n",
|
||||
"\n",
|
||||
"where $\\vec{w}_j$ is the space- and time-discretized approximation to $\\Psi(x_i, t_j)$ with $j$ being the time-discretization index. $\\mathbf{A}$ and $\\mathbf{B}$ are $(m-2)\\times(m-2)$ matrices of the form\n",
|
||||
"\n",
|
||||
"\\begin{align*}\n",
|
||||
"\\mathbf{A} =\n",
|
||||
" \\left( \\begin{array}{cccc}\n",
|
||||
" 1 + \\lambda_1 + \\lambda_2 V_1& -\\frac{\\lambda_1}{2} & & 0\\\\\n",
|
||||
" -\\frac{\\lambda_1}{2} & \\ddots & \\ddots & \\\\\n",
|
||||
" & \\ddots & \\ddots & -\\frac{\\lambda_1}{2} \\\\\n",
|
||||
" 0 & & -\\frac{\\lambda_1}{2} & 1 + \\lambda_1 + \\lambda_2 V_{m-1} \n",
|
||||
" \\end{array} \\right)\n",
|
||||
"\\end{align*}\n",
|
||||
"\n",
|
||||
"and\n",
|
||||
"\n",
|
||||
"\\begin{align*}\n",
|
||||
"\\mathbf{B} =\n",
|
||||
" \\left( \\begin{array}{cccc}\n",
|
||||
" 1 - \\lambda_1 - \\lambda_2 V_1& +\\frac{\\lambda_1}{2} & & 0\\\\\n",
|
||||
" +\\frac{\\lambda_1}{2} & \\ddots & \\ddots & \\\\\n",
|
||||
" & \\ddots & \\ddots & +\\frac{\\lambda_1}{2} \\\\\n",
|
||||
" 0 & & +\\frac{\\lambda_1}{2} & 1 - \\lambda_1 - \\lambda_2 V_{m-1} \n",
|
||||
" \\end{array} \\right).\n",
|
||||
"\\end{align*}\n",
|
||||
"\n",
|
||||
"Derive this form and thereby the definitions of $\\lambda_1$ and $\\lambda_2$. Start with recapping the derivation of the Crank-Nicolson approach (see Wikipedia or *Numerical Analysis* book by Burden and Faires).\n",
|
||||
"\n",
|
||||
"Write your definitions of $\\lambda_1$ and $\\lambda_2$ in the Markdown cell below. (Double click on \"YOUR ANSWER HERE\" to open the cell, and ctrl+enter to compile.) "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
"nbgrader": {
|
||||
"cell_type": "markdown",
|
||||
"checksum": "44809512ee599c3aed3922d7bf58c760",
|
||||
"grade": true,
|
||||
"grade_id": "cell-5934430865cb8756",
|
||||
"locked": false,
|
||||
"points": 2,
|
||||
"schema_version": 3,
|
||||
"solution": true,
|
||||
"task": false
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"YOUR ANSWER HERE"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
"editable": false,
|
||||
"nbgrader": {
|
||||
"cell_type": "markdown",
|
||||
"checksum": "617d1c88d7513c16a283d6f779e735f8",
|
||||
"grade": false,
|
||||
"grade_id": "cell-c0e77a843337deab",
|
||||
"locked": true,
|
||||
"schema_version": 3,
|
||||
"solution": false,
|
||||
"task": false
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"### Task 4\n",
|
||||
"\n",
|
||||
"The equation system from above can be used to calculate the time propagation by multiplying the whole expression from the left by $\\mathbf{A}^{-1}$. The only needed ingredients are the boundary conditions $w_{i=0,j} = w_{i=m-1,j} = 0$ for all $j$ (not explicitly needed, just used for the derivation of $\\mathbf{A}$ and $\\mathbf{B}$) and the initial value $w_{i,j=0} = f(x_i)$. \n",
|
||||
"\n",
|
||||
"Implement the Crank-Nicolson approach for our 1D SEQ in a Python function $\\text{SEQDyn(x, t, V, f)}$, where $\\text{x}$ and $\\text{t}$ are the discretized spatial and time grids, $\\text{V}$ is the potential, and $\\text{f}$ is the function defining the boundary conditions. The function should return a two-dimensional array, which stores the eigenfunction $\\Psi(x_i, t_j)$ at all discretized spatial and time coordinates.\n",
|
||||
"\n",
|
||||
"Apply it to the SEQ from task 2.2, with $V(x) = 0.25 x^2$ and $f(x) = \\operatorname{exp}(-x^2) / 2.5$. Use $-5 \\leq x \\leq +5$ with $100$ steps and $0 \\leq t \\leq 50$ with $1000$ steps. Animate your solution (see exercise 9)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
"nbgrader": {
|
||||
"cell_type": "code",
|
||||
"checksum": "101995c7f2d3fae58c008aba5249bc03",
|
||||
"grade": true,
|
||||
"grade_id": "cell-0285caf76b42668f",
|
||||
"locked": false,
|
||||
"points": 3,
|
||||
"schema_version": 3,
|
||||
"solution": true,
|
||||
"task": false
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def SEQDyn(x, t, V, f):\n",
|
||||
" # YOUR CODE HERE\n",
|
||||
" raise NotImplementedError()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
"nbgrader": {
|
||||
"cell_type": "code",
|
||||
"checksum": "dd33620bad76db58026f0f3969c4deef",
|
||||
"grade": true,
|
||||
"grade_id": "cell-908842d3cfe8780f",
|
||||
"locked": false,
|
||||
"points": 3,
|
||||
"schema_version": 3,
|
||||
"solution": true,
|
||||
"task": false
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Animate your solution here ...\n",
|
||||
"\n",
|
||||
"# YOUR CODE HERE\n",
|
||||
"raise NotImplementedError()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
"editable": false,
|
||||
"nbgrader": {
|
||||
"cell_type": "markdown",
|
||||
"checksum": "ff153ed7134e0e5ce02e07496c481fed",
|
||||
"grade": false,
|
||||
"grade_id": "cell-c7b697a60de4d952",
|
||||
"locked": true,
|
||||
"schema_version": 3,
|
||||
"solution": false,
|
||||
"task": false
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"### [Optional] Task 5\n",
|
||||
"\n",
|
||||
"What happens when your initial condition is set to one of the eigenfunctions you obtained from the static 1D SEQ?"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
"nbgrader": {
|
||||
"cell_type": "code",
|
||||
"checksum": "b37536c5609e25f4d50e90d48c2086fe",
|
||||
"grade": true,
|
||||
"grade_id": "cell-9db256b1ad3624d2",
|
||||
"locked": false,
|
||||
"points": 0,
|
||||
"schema_version": 3,
|
||||
"solution": true,
|
||||
"task": false
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# YOUR CODE HERE\n",
|
||||
"raise NotImplementedError()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
"editable": false,
|
||||
"nbgrader": {
|
||||
"cell_type": "markdown",
|
||||
"checksum": "2187f548a079c7c24ed4d26569038579",
|
||||
"grade": false,
|
||||
"grade_id": "cell-c3897fb054824511",
|
||||
"locked": true,
|
||||
"schema_version": 3,
|
||||
"solution": false,
|
||||
"task": false
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"### [Optional] Task 6\n",
|
||||
"\n",
|
||||
"Change the potential to a staggered one of the form \n",
|
||||
"\n",
|
||||
"\\begin{align*}\n",
|
||||
" V(x) = \\left\\{ \n",
|
||||
" \\begin{array}{cc} \n",
|
||||
" +15 & -4.0 < x < -3.5, \\, -2.5 < x < -2.0, \\, -1.0 < x < -0.5, \\\\ \n",
|
||||
" +15 & +0.5 < x < +1.0, \\, +2.0 < x < +2.5, \\, +3.5 < x < +4.0, \\\\ \n",
|
||||
" 0 & \\text{else}\n",
|
||||
" \\end{array} \\right.\n",
|
||||
"\\end{align*}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"deletable": false,
|
||||
"nbgrader": {
|
||||
"cell_type": "code",
|
||||
"checksum": "63921e0b8a563b6176982116089af413",
|
||||
"grade": true,
|
||||
"grade_id": "cell-0dc7ed106484a47b",
|
||||
"locked": false,
|
||||
"points": 0,
|
||||
"schema_version": 3,
|
||||
"solution": true,
|
||||
"task": false
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# YOUR CODE HERE\n",
|
||||
"raise NotImplementedError()"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.10"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 4
|
||||
}
|
||||
Reference in New Issue
Block a user