Skip to content

Commit

Permalink
'cookbook added'
Browse files Browse the repository at this point in the history
  • Loading branch information
DPotoyan authored Aug 26, 2024
1 parent d87f834 commit 3180adf
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 27 deletions.
2 changes: 1 addition & 1 deletion _toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ parts:
- file: ch08/note09
- file: ch08/demo_h2plus
- file: scratch
- file: units
- file: cookbook
- file: overview

- caption: Extra stuff
Expand Down
141 changes: 141 additions & 0 deletions cookbook.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Cookbook: Using python to tame the math"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np \n",
"import matplotlib.pyplot as plt\n",
"from ipywidgets import interact\n",
"import scipy \n",
"from scipy.constants import physical_constants, hbar, h, c, k, m_e, Rydberg, e, N_A\n",
"\n",
"%matplotlib inline\n",
"%config InlineBackend.figure_format='retina'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Example-1\n",
"\n",
"- Show that wavefunctions $f_1 = sin(x)$ and $f_2=cos(x)$ are orthogonal on $(0, 2\\pi)$ interval."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Numerical solution"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"# Define the range of x values\n",
"x = np.linspace(0, 2 * np.pi, 1000)\n",
"\n",
"# Calculate sin(x) and cos(x)\n",
"y_sin = np.sin(x)\n",
"y_cos = np.cos(x)\n",
"\n",
"# Calculate the numerical integral (dot product)\n",
"dot_product = np.trapz(y_sin * y_cos, x)\n",
"\n",
"# Print the result\n",
"print(f\"The numerical integral (dot product) of sin(x) * cos(x) over [0, 2π] is approximately: {dot_product:.4f}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Symbolic solution"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"import sympy as sp\n",
"\n",
"# Define the symbolic variable\n",
"x = sp.symbols('x')\n",
"\n",
"# Define sin(x) and cos(x)\n",
"sin_x = sp.sin(x)\n",
"cos_x = sp.cos(x)\n",
"\n",
"# Calculate the symbolic integral of sin(x) * cos(x) over [0, 2π]\n",
"integral = sp.integrate(sin_x * cos_x, (x, 0, 2 * sp.pi))\n",
"\n",
"# Print the result\n",
"print(f\"The symbolic integral of sin(x) * cos(x) over [0, 2π] is: {integral}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Visual solution"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"def plot_orthogonality():\n",
"\n",
" # Define the range of x values\n",
" x = np.linspace(0, 2 * np.pi, 1000)\n",
" \n",
" # Calculate sin(x) and cos(x)\n",
" y_sin = np.sin(x)\n",
" y_cos = np.cos(x)\n",
" \n",
" # Plotting sin(x) and cos(x)\n",
" plt.plot(x, y_sin, label='sin(x)')\n",
" plt.plot(x, y_cos, label='cos(x)')\n",
" \n",
" # Fill the area between two horizontal curves\n",
" plt.fill_between(x, y_sin * y_cos, alpha=0.3, color='gray', label='sin(x) * cos(x)')\n",
" \n",
" # Labels and title\n",
" plt.xlabel('x')\n",
" plt.ylabel('Function Value')\n",
" plt.title('Orthogonality of sin(x) and cos(x)')\n",
" plt.legend()\n",
" plt.grid(True)\n",
" plt.show()\n",
"\n",
"# Call the function\n",
"plot_orthogonality()"
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
25 changes: 25 additions & 0 deletions overview.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
# Equation sheet

## Units

### Constants
| Energy Constant | Value |
|:----------------|--------------------:|
| $h = 6.63 \cdot 10^{-34} \, [J \cdot s]$ | $m_u = 1.66 \cdot 10^{-27} \, [kg]$ |
| $k_B = 1.38 \cdot 10^{-23} \, [J \cdot K^{-1}]$ | $N_A = 6.02 \cdot 10^{23} \, [mol^{-1}]$ |
| $c = 3.0 \cdot 10^{8} \, [m \cdot s^{-1}]$ | $m_e = 9.1093837015 \cdot 10^{-31} \, [kg]$ |
| $R_H = 109680 \, [cm^{-1}]$ | $e = 1.602176634 \cdot 10^{-19} \, [C]$ |


### Energy Unit Converter

- See [here](https://www.weizmann.ac.il/oc/martin/tools/hartree.html) for an interactive option.

| Unit | $J$ | $eV$ | $cm^{-1}$ | $hartree$ | $Hz$ |
|:----:|:---:|:----:|:---------:|:---------:|:----:|
| $J$ | $1$ | $6.24181 \cdot 10^{18}$ | $5.03445 \cdot 10^{22}$ | $2.294 \cdot 10^{17}$ | $1.50930 \cdot 10^{33}$ |
| $eV$ | $1.60210 \cdot 10^{-19}$ | $1$ | $8065.73$ | $0.0367502$ | $2.41804 \cdot 10^{14}$ |
| $cm^{-1}$ | $1.98630 \cdot 10^{-23}$ | $1.23981 \cdot 10^{-4}$ | $1$ | $4.55633 \cdot 10^{-6}$ | $2.99793 \cdot 10^{10}$ |
| $hartree$ | $43.60 \cdot 10^{-19}$ | $27.2107$ | $219474.63$ | $1$ | $6.57966 \cdot 10^{15}$ |
| $Hz$ | $6.62561 \cdot 10^{-34}$ | $4.13558 \cdot 10^{-15}$ | $3.33565 \cdot 10^{-11}$ | $1.51983 \cdot 10^{-16}$ | $1$ |


## From classical to Quantum

### Blackbody radiation
Expand Down
26 changes: 0 additions & 26 deletions units.md

This file was deleted.

0 comments on commit 3180adf

Please sign in to comment.