fixing the nonlinear equation residual calculation.