Energy dependence of the optical potential from a dispersion relation