Analytical calculation of permanent magnet couplings