Some examples
1D Real
\begin{align}
\frac{\mathrm{d}}{\mathrm{d}t}y(t) = 2 t y(t)
\end{align}
exact solution is
\begin{align} y(t) = e^{t^2}y(0) \end{align}import numpy as np |
1D Complex
\begin{align}
\frac{d}{\mathrm{d}t}\psi = f(t) \psi
\end{align}
Write as
\begin{align} \frac{\mathrm{d}}{\mathrm{d}t} \begin{pmatrix} \mathrm{Re}\psi(t) \\ \mathrm{Im}\psi(t) \end{pmatrix} = \begin{pmatrix} \mathrm{Re} f(t) & -\mathrm{Im} f(t)\\ \mathrm{Im} f(t) & \mathrm{Re} f(t) \end{pmatrix} \begin{pmatrix} \mathrm{Re}\psi(t) \\ \mathrm{Im}\psi(t) \end{pmatrix} \end{align}For example
\begin{align} \frac{d}{\mathrm{d}t}\psi = \mathrm{i}\omega \psi \end{align}exact solution is
\begin{align} \psi = e^{\mathrm{i}(\omega t + \phi_0)} \end{align}import numpy as np |
2D Real
A Van der Pol oscillator
\begin{align} \frac{\mathrm{d}^2}{\mathrm{d}t^2}x(t) - \mu\left[1 - x(t)^2\right] \frac{\mathrm{d}}{\mathrm{d}t}x(t) + x(t) =0 \end{align}Can write as
\begin{align} \frac{\mathrm{d}}{\mathrm{d}t} \begin{pmatrix} x(t) \\ x'(t) \end{pmatrix} = \begin{pmatrix} x'(t) \\ \mu\left[1 - x(t)^2\right] x'(t) - x(t) \end{pmatrix} \end{align}import numpy as np |
2D Complex
Rabi oscillation(ref: another post)
\begin{align*} \mathrm{i}\hbar\dot{c}_1 =& \gamma e^{\mathrm{i}(\omega-\omega_{21})t} c_2 \tag{1}\\ \mathrm{i}\hbar\dot{c}_2 =&\gamma e^{-\mathrm{i}(\omega-\omega_{21})t} c_1\tag{2} \end{align*}exact solution is
\begin{align} |c_2(t)|^2 = \frac{1}{1+\frac{\hbar^2(\omega-\omega_{21})^2}{4\gamma^2}}\sin^2\left( \Omega t \right) \end{align}where
\begin{align} \Omega = \sqrt{\frac{(\omega-\omega_{21})^2}{4}+\frac{\gamma^2}{\hbar^2}} \end{align}In numerical calculation, we set \(\hbar = 1, \gamma = 1, \Delta\omega = \omega - \omega_{21}\) , then
\begin{align} \frac{\mathrm{d}}{\mathrm{d}t} \begin{pmatrix} \mathrm{Re} c_1 \\ \mathrm{Im} c_1 \\ \mathrm{Re}c_2 \\ \mathrm{Im}c_2 \end{pmatrix} = \begin{pmatrix} 0 & 0 & \sin\Delta\omega t & \cos\Delta\omega t \\ 0 & 0 & -\cos\Delta\omega t & \sin\Delta\omega t \\ -\sin\Delta\omega t & \cos\Delta\omega t & 0 & 0 \\ -\cos\Delta\omega t & -\sin\Delta\omega t & 0 & 0 \\ \end{pmatrix} \begin{pmatrix} \mathrm{Re} c_1 \\ \mathrm{Im} c_1 \\ \mathrm{Re}c_2 \\ \mathrm{Im}c_2 \end{pmatrix} \end{align}import numpy as np |