Ahilan Kumaresan commited on
Commit
f3feb4b
·
1 Parent(s): a5ec874

some markdown updates

Browse files
Files changed (2) hide show
  1. ModularedPresentation.ipynb +247 -0
  2. app.py +1 -1
ModularedPresentation.ipynb CHANGED
@@ -55,6 +55,242 @@
55
  " - Documentation + modular design\n"
56
  ]
57
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  {
59
  "cell_type": "markdown",
60
  "metadata": {},
@@ -1381,6 +1617,17 @@
1381
  "source": [
1382
  "plot_dead(E=E_vals, psi=psi_vecs, V=V_full, x=x, nos=5);\n"
1383
  ]
 
 
 
 
 
 
 
 
 
 
 
1384
  }
1385
  ],
1386
  "metadata": {
 
55
  " - Documentation + modular design\n"
56
  ]
57
  },
58
+ {
59
+ "cell_type": "markdown",
60
+ "metadata": {},
61
+ "source": [
62
+ "---\n",
63
+ "\n",
64
+ "## 0. Quantum picture: what am I actually solving?\n",
65
+ "\n",
66
+ "Before getting lost in matrices and `numpy`, I want to be clear what the **physics problem** is.\n",
67
+ "\n",
68
+ "In the postulate language of quantum mechanics:\n",
69
+ "\n",
70
+ "- A **state** of the particle is described by a wavefunction $$\\Psi(x)$$ \n",
71
+ " (or more abstractly, a vector $$|\\Psi\\rangle$$ in a Hilbert space).\n",
72
+ "\n",
73
+ "- **Observables** (like energy) are represented by **Hermitian operators**.\n",
74
+ " For a particle in 1D with potential $$V(x)$$, the Hamiltonian operator is\n",
75
+ "\n",
76
+ " $$\n",
77
+ " \\hat{H} = -\\frac{\\hbar^2}{2m}\\frac{d^2}{dx^2} + V(x).\n",
78
+ " $$\n",
79
+ "\n",
80
+ "- The **energy eigenstates** are solutions of\n",
81
+ "\n",
82
+ " $$\n",
83
+ " \\hat{H}\\,\\psi_n(x) = E_n \\,\\psi_n(x),\n",
84
+ " $$\n",
85
+ "\n",
86
+ " with boundary conditions and normalization:\n",
87
+ "\n",
88
+ " $$\n",
89
+ " \\int |\\psi_n(x)|^2 dx = 1.\n",
90
+ " $$\n",
91
+ "\n",
92
+ "Physically:\n",
93
+ "\n",
94
+ "- Each $$\\psi_n(x)$$ is a **stationary state**: if the system is prepared in $$\\psi_n$$, the probability density\n",
95
+ " $$|\\psi_n(x,t)|^2$$ is independent of time (it only picks up a phase $$e^{-iE_n t/\\hbar}$$).\n",
96
+ "\n",
97
+ "- The energies $$E_n$$ are the possible outcomes of a precise **energy measurement**.\n",
98
+ "\n",
99
+ "- A general state can be expanded as\n",
100
+ "\n",
101
+ " $$\n",
102
+ " \\Psi(x,0) = \\sum_n c_n \\psi_n(x),\n",
103
+ " $$\n",
104
+ "\n",
105
+ " and then evolves as\n",
106
+ "\n",
107
+ " $$\n",
108
+ " \\Psi(x,t) = \\sum_n c_n \\psi_n(x)\\,e^{-iE_n t/\\hbar}.\n",
109
+ " $$\n",
110
+ "\n",
111
+ "So my numerical solver is really a machine that takes a **chosen potential** $$V(x)$$ and returns:\n",
112
+ "\n",
113
+ "- The discrete spectrum $$\\{E_n\\}$$ (energy levels for that potential).\n",
114
+ "- The corresponding eigenfunctions $$\\psi_n(x)$$ (stationary states).\n",
115
+ "\n",
116
+ "Once I have those, I can in principle build **any** time-dependent solution by choosing coefficients $$c_n$$.\n",
117
+ "\n",
118
+ "\n",
119
+ "---\n"
120
+ ]
121
+ },
122
+ {
123
+ "cell_type": "markdown",
124
+ "metadata": {},
125
+ "source": [
126
+ "# %% [markdown]\n",
127
+ "### 2.2.1 Infinite wall as a limit of a finite barrier\n",
128
+ "\n",
129
+ "Another way to see $$\\Psi(0) = \\Psi(a) = 0$$:\n",
130
+ "\n",
131
+ "- Start with a **finite** but huge barrier outside $$[0,a]$$:\n",
132
+ " \n",
133
+ " - $$V(x) = 0$$ for $$0 < x < a$$,\n",
134
+ " - $$V(x) = V_0$$ (large but finite) for $$x \\le 0$$ and $$x \\ge a$$.\n",
135
+ "\n",
136
+ "- For a bound state with energy $$E < V_0$$, the solution in the barrier region decays exponentially\n",
137
+ " (evanescent tail). As $$V_0 \\to \\infty$$, the decay length goes to zero, and the wavefunction is\n",
138
+ " squeezed to exactly zero at the wall.\n",
139
+ "\n",
140
+ "So the infinite square well is an **idealized limit** where those evanescent tails are completely killed.\n",
141
+ "In that limit, the physically acceptable states are exactly those that vanish at the boundaries.\n",
142
+ "\n",
143
+ "### 2.2.2 Probability current and “no leakage”\n",
144
+ "\n",
145
+ "The boundary conditions are also tied to **probability conservation**.\n",
146
+ "\n",
147
+ "The probability current in 1D is\n",
148
+ "\n",
149
+ "$$\n",
150
+ "j(x) = \\frac{\\hbar}{m}\\,\\text{Im}\\big(\\Psi^*(x)\\,\\partial_x \\Psi(x)\\big).\n",
151
+ "$$\n",
152
+ "\n",
153
+ "For a particle trapped in the well, there should be **no net probability flow out** of the region.\n",
154
+ "Taking $$\\Psi(0) = \\Psi(a) = 0$$ ensures that $$j(0) = j(a) = 0$$, so there is no leakage of probability\n",
155
+ "through the walls. This is part of making $$\\hat{H}$$ self-adjoint with these boundary conditions.\n",
156
+ "\n",
157
+ "---"
158
+ ]
159
+ },
160
+ {
161
+ "cell_type": "markdown",
162
+ "metadata": {},
163
+ "source": [
164
+ "# %% [markdown]\n",
165
+ "### 2.3.1 Physical interpretation: standing waves, nodes, and quantization\n",
166
+ "\n",
167
+ "The infinite well is a quantum version of a **string fixed at both ends**:\n",
168
+ "\n",
169
+ "- The boundary conditions $$\\Psi(0) = \\Psi(a) = 0$$ only allow certain “standing wave” shapes.\n",
170
+ "- Those shapes are exactly\n",
171
+ "\n",
172
+ " $$\n",
173
+ " \\Psi_n(x) = \\sqrt{\\frac{2}{a}} \\sin\\left(\\frac{n\\pi x}{a}\\right),\n",
174
+ " $$\n",
175
+ "\n",
176
+ " with integer $$n = 1,2,3,\\dots$$\n",
177
+ "\n",
178
+ "Each $$n$$ has:\n",
179
+ "\n",
180
+ "- $$n-1$$ internal **nodes** (points where $$\\Psi_n(x) = 0$$ inside the well).\n",
181
+ "- Increasing **curvature** of the wavefunction, which corresponds to higher kinetic energy.\n",
182
+ "\n",
183
+ "This is why the energies scale like\n",
184
+ "\n",
185
+ "$$\n",
186
+ "E_n \\propto n^2.\n",
187
+ "$$\n",
188
+ "\n",
189
+ "The key physics point:\n",
190
+ "\n",
191
+ "- The **discreteness** of the spectrum (energy quantization) is not put in by hand.\n",
192
+ "- It **emerges** from:\n",
193
+ " - the wave nature of the particle, and\n",
194
+ " - the boundary conditions (particle confined in a finite region).\n",
195
+ "\n",
196
+ "My numerical solver is reproducing that spectrum purely from the operator\n",
197
+ "\n",
198
+ "$$\n",
199
+ "\\hat{H} = -\\frac{\\hbar^2}{2m}\\frac{d^2}{dx^2} + V(x)\n",
200
+ "$$\n",
201
+ "\n",
202
+ "and the boundary conditions encoded in the matrix.\n",
203
+ "---\n"
204
+ ]
205
+ },
206
+ {
207
+ "cell_type": "markdown",
208
+ "metadata": {},
209
+ "source": [
210
+ "\n",
211
+ "## 6. Using the numerical eigenstates as actual quantum states\n",
212
+ "\n",
213
+ "Once I have the eigenvalues $$E_n$$ and eigenvectors $$\\psi_n(x_i)$$ on the grid, I can treat them as\n",
214
+ "**full quantum states** and compute observables.\n",
215
+ "\n",
216
+ "On the grid, an integral becomes a sum:\n",
217
+ "\n",
218
+ "$$\n",
219
+ "\\int f(x)\\,dx \\approx \\sum_i f(x_i)\\,\\Delta x.\n",
220
+ "$$\n",
221
+ "\n",
222
+ "So for a normalized eigenstate $$\\psi_n(x)$$:\n",
223
+ "\n",
224
+ "- Position expectation value:\n",
225
+ "\n",
226
+ " $$\n",
227
+ " \\langle x \\rangle_n \\approx \\sum_i x_i\\,|\\psi_n(x_i)|^2\\,\\Delta x.\n",
228
+ " $$\n",
229
+ "\n",
230
+ "- Position variance:\n",
231
+ "\n",
232
+ " $$\n",
233
+ " \\Delta x_n^2 = \\langle x^2 \\rangle_n - \\langle x \\rangle_n^2.\n",
234
+ " $$\n",
235
+ "\n",
236
+ "For momentum, in the position representation\n",
237
+ "\n",
238
+ "$$\n",
239
+ "\\hat{p} = -i\\hbar \\frac{d}{dx}.\n",
240
+ "$$\n",
241
+ "\n",
242
+ "On the grid, I can approximate the derivative with finite differences, e.g.\n",
243
+ "\n",
244
+ "$$\n",
245
+ "\\left.\\frac{d\\psi}{dx}\\right|_{x_i} \\approx \\frac{\\psi(x_{i+1}) - \\psi(x_{i-1})}{2\\Delta x},\n",
246
+ "$$\n",
247
+ "\n",
248
+ "and then build\n",
249
+ "\n",
250
+ "$$\n",
251
+ "\\langle p \\rangle_n \\approx \\sum_i \\psi_n^*(x_i)\\,\\left(-i\\hbar \\frac{d\\psi_n}{dx}\\bigg|_{x_i}\\right)\\Delta x.\n",
252
+ "$$\n",
253
+ "\n",
254
+ "Similarly for $$\\langle p^2 \\rangle_n$$, which lets me compute $$\\Delta p_n$$ and check the\n",
255
+ "uncertainty relation numerically:\n",
256
+ "\n",
257
+ "$$\n",
258
+ "\\Delta x_n\\,\\Delta p_n \\ge \\frac{\\hbar}{2}.\n",
259
+ "$$\n",
260
+ "\n",
261
+ "So the solver is not just a “pretty plotter” of eigenfunctions; it is a tool to compute\n",
262
+ "**quantum expectation values** for arbitrary observables once they are discretized on the grid.\n"
263
+ ]
264
+ },
265
+ {
266
+ "cell_type": "markdown",
267
+ "metadata": {},
268
+ "source": [
269
+ "\n",
270
+ "### 3.5 Operator viewpoint: matrix = Hamiltonian in a finite basis\n",
271
+ "\n",
272
+ "Conceptually, what I’ve done is:\n",
273
+ "\n",
274
+ "- Start from the abstract operator equation\n",
275
+ "\n",
276
+ " $$\n",
277
+ " \\hat{H}|\\psi_n\\rangle = E_n |\\psi_n\\rangle,\n",
278
+ " $$\n",
279
+ "\n",
280
+ "- Choose the **position basis** sampled on a grid\n",
281
+ " $$\\{|x_1\\rangle, |x_2\\rangle, \\dots, |x_{N-1}\\rangle\\},$$\n",
282
+ "- Represent $$\\hat{H}$$ as an $$N\\times N$$ **matrix** in that basis using finite differences for the kinetic term\n",
283
+ " and a diagonal matrix for $$V(x)$$.\n",
284
+ "\n",
285
+ "Because $$\\hat{H}$$ is Hermitian (and my discrete approximation respects that symmetry), the matrix is:\n",
286
+ "\n",
287
+ "- Real symmetric,\n",
288
+ "- Has **real** eigenvalues,\n",
289
+ "- And its eigenvectors form an **orthonormal basis** of the grid space.\n",
290
+ "\n",
291
+ "This is exactly what I see in the overlap matrix: numerically, it is very close to the identity.\n"
292
+ ]
293
+ },
294
  {
295
  "cell_type": "markdown",
296
  "metadata": {},
 
1617
  "source": [
1618
  "plot_dead(E=E_vals, psi=psi_vecs, V=V_full, x=x, nos=5);\n"
1619
  ]
1620
+ },
1621
+ {
1622
+ "cell_type": "markdown",
1623
+ "metadata": {},
1624
+ "source": [
1625
+ "Deploy:\n",
1626
+ "\n",
1627
+ "\n",
1628
+ "https://huggingface.co/spaces/AhiBucket/Hand-wave\n",
1629
+ "\n"
1630
+ ]
1631
  }
1632
  ],
1633
  "metadata": {
app.py CHANGED
@@ -419,7 +419,7 @@ elif page == "Benchmarks & Verification":
419
  This solver has been rigorously tested against known analytical solutions and external libraries to ensure physical accuracy.
420
  """)
421
 
422
- tab1, tab2, tab3 = st.tabs(["Analytical Benchmarks", "QMSolve Comparison", "Hamiltonian Check"])
423
 
424
  with tab1:
425
  st.subheader("1. Infinite Square Well")
 
419
  This solver has been rigorously tested against known analytical solutions and external libraries to ensure physical accuracy.
420
  """)
421
 
422
+ tab1, tab2, tab3 = st.tabs(["Analytical Benchmarks", "QMSolve Comparison", "Code"])
423
 
424
  with tab1:
425
  st.subheader("1. Infinite Square Well")