Speed of a planet in an elliptical orbit with semi major axis 'a' about sun of mass M at a distance r from sun is
Total energy of a planet in an ellipitcal orbit is:
E=−GMm2a (m = mass of planet)
From conservation of mechanical energy
KE + PE = E
or 12mv2−GMmr=−GMm2a
or v=√GM(2r−1a)