Correlated X-Ray and Optical Variability in Markarian 509