Create anonymous function for magnitude