Consider a Hamiltonian system (e.g. the mathematical pendulum). I used the symplectic (Euler) method (or Leapfrog) and the explicit Euler to solve it. I run a Matlab code to compute the Hamiltonian of the system (e.g.) when applying both methods.
In the explicit Euler case, the energy is not preserved even if I change the steps to very small. But this is weird to me, because the solution must approach to the real solution, but actual solutions does preserve the energy.
In the symplectic case, the energy is not being preserved either, but oscillating around the initial energy. But as I learnt symplectic method does preserve the energy?
I'll give a quick answer in words, although I am sure others can give much more rigorous answers supported by equations.
The explicit Euler method only approximately conserves the true energy. The symplectic method exactly conserves a property which is approximately equal to the true energy. There's a subtle difference.
In the first case, you can define the local error of the method, and it becomes more accurate as you reduce the step size $\Delta t$, but there is nothing acting globally to stop the energy drifting: it is not conserved. In the second case, there is a shadow hamiltonian which is equal to the true hamiltonian plus a correction term of order $\Delta t^2$. This shadow hamiltonian is exactly conserved. So this means that the measured energy will fluctuate around the true constant-energy surface of the dynamics.
In most cases, we can't calculate the correction term exactly, but can show that it has an expansion in $\Delta t$ provided the hamiltonian is reasonably smoothly behaved. But in the case of the simple harmonic oscillator, actually, you can obtain an algebraic expression for the shadow hamiltonian and prove that it is exactly conserved by the leapfrog algorithm. It is an instructive (if slightly tedious) exercise to do this.