Prestack depth migration provides a powerful tool for velocity analysis in complex media. Both prominent approaches to velocity analysis-depth-focusing analysis and residual-curvature analysis, rely on approximate formulas to update velocity. Generally, these formulas are derived under the assumptions of horizontal reflector, lateral velocity homogeneity, or small offset. Therefore, the conventional methods for updating velocity lack accuracy and computational efficiency when velocity has large, lateral variations. Here, based on ray theory, I find the analytic representation for the derivative of imaged depths with respect to migration velocity. This derivative function characterizes a general relationship between residual moveout and residual velocity. Using the derivative function and the perturbation method, I derive a new formula to update velocity from residual moveout. In the derivation, I impose no limitation on offset, dip, or velocity distribution. Consequently, I revise the residual-curvature-analysis method for velocity estimation in the postmigrated domain. Furthermore, my formula provides sensitivity and error estimation for migration-based velocity analysis, which is helpful in quantifying the reliability of the estimated velocity. The theory and methodology in this paper have been tested on synthetic data (including the Marmousi data).