|
| 1 | +--- |
| 2 | +jupyter: |
| 3 | + jupytext: |
| 4 | + text_representation: |
| 5 | + extension: .md |
| 6 | + format_name: markdown |
| 7 | + format_version: '1.3' |
| 8 | + jupytext_version: 1.13.8 |
| 9 | + kernelspec: |
| 10 | + display_name: Python 3 (ipykernel) |
| 11 | + language: python |
| 12 | + name: python3 |
| 13 | +--- |
| 14 | + |
| 15 | +# Using qutip.distributions |
| 16 | + |
| 17 | +Author: Mathis Beaudoin (2025) |
| 18 | + |
| 19 | +### Introduction |
| 20 | + |
| 21 | +This notebook shows how to use probability distributions inside QuTiP. We begin by importing the necessary packages. |
| 22 | + |
| 23 | +```python |
| 24 | +from qutip import fock, about |
| 25 | +from qutip.distributions import HarmonicOscillatorWaveFunction |
| 26 | +from qutip.distributions import HarmonicOscillatorProbabilityFunction |
| 27 | +import matplotlib.pyplot as plt |
| 28 | +``` |
| 29 | + |
| 30 | +### Harmonic Oscillator Wave Function |
| 31 | + |
| 32 | +Here, we display the spatial distribution of the wave function for the harmonic oscillator (n=0 to n=7) with the `HarmonicOscillatorWaveFunction()` class. |
| 33 | + |
| 34 | +Optionally, define a range of values for each coordinate with the parameter called `extent`. Also, define a number of data points inside the given range with the optional parameter called `steps`. From this information, the distribution is generated and can be visualized with the `.visualize()` method. |
| 35 | + |
| 36 | +```python |
| 37 | +M = 8 |
| 38 | +N = 20 |
| 39 | + |
| 40 | +fig, ax = plt.subplots(M, 1, figsize=(10, 12), sharex=True) |
| 41 | + |
| 42 | +for n in range(M): |
| 43 | + psi = fock(N, n) |
| 44 | + wf = HarmonicOscillatorWaveFunction(psi, 1.0, extent=[-10, 10]) |
| 45 | + wf.visualize(fig=fig, ax=ax[M-n-1], show_ylabel=False, show_xlabel=(n == 0)) |
| 46 | +``` |
| 47 | + |
| 48 | +### Harmonic Oscillator Probability Function |
| 49 | + |
| 50 | +The class `HarmonicOscillatorProbabilityFunction()` is the squared magnitude of the data that would normally be in `HarmonicOscillatorWaveFunction()`. We use the same example as before. |
| 51 | + |
| 52 | +```python |
| 53 | +M = 8 |
| 54 | +N = 20 |
| 55 | + |
| 56 | +fig, ax = plt.subplots(M, 1, figsize=(10, 12), sharex=True) |
| 57 | + |
| 58 | +for n in range(M): |
| 59 | + psi = fock(N, n) |
| 60 | + wf = HarmonicOscillatorProbabilityFunction(psi, 1.0, extent=[-10, 10]) |
| 61 | + wf.visualize(fig=fig, ax=ax[M-n-1], show_ylabel=False, show_xlabel=(n == 0)) |
| 62 | +``` |
| 63 | + |
| 64 | +### About |
| 65 | + |
| 66 | +```python |
| 67 | +about() |
| 68 | +``` |
0 commit comments