-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a7bae69
commit 6f92596
Showing
14 changed files
with
569 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,274 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"cell_id": "00000-41034960-cfcd-40d6-9234-767d7fb048c0", | ||
"deepnote_cell_type": "markdown", | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"<center>\n", | ||
"\n", | ||
"# Python for Quantum Mechanics: \n", | ||
"# Week 5: Excercises\n", | ||
"\n", | ||
"</center>" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Exercise 1: Settlers of Histogram" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Imagine a game that involves rolling two dice (six sided) and adding the results. Knowing the most likely outcomes is important for doing well in this game so you want to run a simulation of the dice rolls. Make a historgam of the results for 1000 rolls.\n", | ||
"\n", | ||
"<img src=\"images/two_dice.png\" alt=\"two dice\" width=\"200\"/>" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"cell_id": "00008-772c311d-21f4-410e-beaf-efffd80e4261", | ||
"deepnote_cell_type": "markdown", | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"## Exercise 2: Normal Distribution" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"cell_id": "00009-cda71b4c-8576-4de0-b957-104af25d30c7", | ||
"deepnote_cell_type": "markdown", | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"A gaussian curve with mean $\\mu$ and standard deviation $\\sigma$ is given by\n", | ||
"$$g(x)=\\frac{1}{\\sigma\\sqrt{2\\pi}} \\exp{\\left( - \\frac{1}{2} \\frac{(x-\\mu)^2}{\\sigma^2} \\right)}.$$" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"cell_id": "00009-df9016c5-a72f-49e2-9983-ce181e0c522f", | ||
"deepnote_cell_type": "code", | ||
"deepnote_to_be_reexecuted": false, | ||
"execution_millis": 2, | ||
"execution_start": 1625584655936, | ||
"source_hash": "94f0f69a", | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"def gaus(x,sig=1,mu=0):\n", | ||
" return (1/(sig*np.sqrt(2*np.pi)))*np.exp(-.5*((x-mu)/sig)**2)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Make a plot of a normal distribution histogram with a gaussian curve overlayed on it." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Plot the following function using `plot_surface()`\n", | ||
"$$G(x,y)=g\\left( \\sqrt{x^2+y^2} \\right)$$" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def gaus3d(x,y,sig=1,mu=0):\n", | ||
" return gaus(np.sqrt(x**2 + y**2))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"cell_id": "00004-cde4d2de-e564-4d94-b44f-92a484a4db84", | ||
"deepnote_cell_type": "markdown", | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"## Exercise 3: Particle in a Box" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Use the following functions to make an animation of the real and imaginary parts of a particle in a box for any $n$.\n", | ||
"<img src=\"images/box_potential.png\" alt=\"two dice\" width=\"200\"/>" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"cell_id": "00005-3ff582d0-f068-4e29-891b-6f072d320e50", | ||
"deepnote_cell_type": "code", | ||
"deepnote_to_be_reexecuted": false, | ||
"execution_millis": 599, | ||
"execution_start": 1625584445278, | ||
"source_hash": "453b36cb", | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"def psi(n,x,l):\n", | ||
" return np.sqrt(2/l) * np.sin(n*np.pi*x/l)\n", | ||
"\n", | ||
"def energy(n):\n", | ||
" return -13.6/n**2\n", | ||
"\n", | ||
"def psi_im(n,x,t,l):\n", | ||
" return np.sin(-t*energy(n)) * psi(n,x,l)\n", | ||
"\n", | ||
"def psi_re(n,x,t,l):\n", | ||
" return np.cos(-t*energy(n)) * psi(n,x,l)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Now put the real and imaginary parts on the $y$ and $z$ axes of a 3D plot." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"cell_id": "00010-fcb17d54-1761-4e8c-9c73-907da40219c1", | ||
"deepnote_cell_type": "markdown", | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"## Exercise 4: Plotting a Sphere" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"You can parameterize a sphere of radius $r$ with parameters $u \\in [0,2\\pi]$ and $v \\in [0,\\pi]$ \n", | ||
"\n", | ||
"$x = r \\cos(u)\\sin(v)$\n", | ||
"\n", | ||
"$y = r \\cos(u)\\sin(v)$\n", | ||
"\n", | ||
"$z = r \\cos(u)\\sin(v)$\n", | ||
"\n", | ||
"Plot a 3D sphere of radius $r=3$." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Exercise 5: Snake Animation" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Reproduce the following animation of a line going around a spiral.\n", | ||
"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"colab": { | ||
"collapsed_sections": [], | ||
"name": "PyQM_Ex.1_sol.ipynb", | ||
"provenance": [] | ||
}, | ||
"deepnote": {}, | ||
"deepnote_execution_queue": [], | ||
"deepnote_notebook_id": "290fde53-7326-4351-a186-a6f6bc6d504a", | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"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.8" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 1 | ||
} |
Oops, something went wrong.