Mathematical Model of the Evolution of Locomotion in Tetrapods