Collisionless spin dynamics in a magnetic field gradient