Calculating the moment of inertia