Method for calculating a Lyapunov exponent