X-Ray and Optical Variability of the Ultraluminous X-Ray Source NGC 1313 X-2