Exercise (Nonlinear oscillator for a complex field).
Consider a field $\psi\in\mathbb{C}$ satisfying the equation
\begin{equation} \label{eq:oscillator}
i \frac{d\psi}{dt} = -\omega\psi + g |\psi|^2\psi.
\end{equation}
(a) Find analytically a solution of this equation when (i) $g=0$ and (ii) $g\neq 0$. [Hint. Note that $d|\psi|^2/dt=0$.]
(b) Show by explicit calculation that Eq. \eqref{eq:oscillator} can be written as
\[
i \frac{d\psi}{dt} = \frac{\partial E}{\partial \psi^*}
\]
where star (*) denotes complex conjugation and $E$ is an energy function,
\begin{equation} \label{eq:energy}
E = \frac{g}{2} |\psi|^4 - \omega|\psi|^2.
\end{equation}
(c) Write explicitely the equation
\begin{equation} \label{eq:dissipative}
i \frac{d\psi}{dt} = (1-i) \frac{\partial E}{\partial \psi^*}
\end{equation}
and prove that $dE/dt \leq 0$.
(d) Write code to solve numerically Eq. \eqref{eq:dissipative} with arbitrary initial condition $\psi(t=0)=\psi_0$ and relate your result to the solution found in (a).
[Hint. You may use Euler's method for numerical integration.]