Nonlinear least squares and nonlinearly constrained optimization