I am trying to sketch the phase portrait of the second order ODE describing a pendulum near the origin:
$$\ddot{x}+\sin(x)=0.$$
I write this as the first order system:
$$ \begin{aligned} \dot{x} &= y \\ \dot{y} &= -\sin(x) \end{aligned} $$
The Jacobian at the origin is given by:
$$ J(0,0) = \begin{pmatrix} 0 & 1\\ -1 & 0 \end{pmatrix} $$
thus giving us eigenvalues $\pm i$ and resulting in a non-hyperbolic fixed point. The system has energy
$$ E = \frac{1}{2}y^{2}+1-\cos(x) $$
and so it is a gradient field. A well-known result is that gradient fields do not have cycles. However, searching online, I came across the plot:
I am not sure where I went wrong. Any help would be greatly appreciated.
No, it is not a gradient field. In particular, it is not the gradient of the energy $E$. On the contrary: the energy $E$ is conserved. Thus the trajectories are the curves of constant $E$.