compute magnitude