add method to calculate magnitude