### 39.3 Weighted Nonlinear Least-Squares

Weighted nonlinear least-squares fitting minimizes the function

    \Phi(x) = (1/2) || f(x) ||_W^2
            = (1/2) \sum_{i=1}^{n} f_i(x_1, ..., x_p)^2

where W = diag(w_1,w_2,...,w_n) is the weighting matrix, and ||f||_W^2 = f^T W f. The weights w_i are commonly defined as w_i = 1/\sigma_i^2, where \sigma_i is the error in the ith measurement. A simple change of variables \tilde{f} = W^{1 \over 2} f yields \Phi(x) = {1 \over 2} ||\tilde{f}||^2, which is in the same form as the unweighted case. The user can either perform this transform directly on their function residuals and Jacobian, or use the `gsl_multifit_nlinear_winit` interface which automatically performs the correct scaling. To manually perform this transformation, the residuals and Jacobian should be modified according to

    f~_i = f_i / \sigma_i
    J~_ij = 1 / \sigma_i df_i/dx_j

For large systems, the user must perform their own weighting.