C-PLOT

Scientific Graphics and Data Analysis

12.21.7. - The fitting equation



In the next part of the code you perform the actual evaluation of your fitting equation. The simple example shown is for fitting to a straight line.
double  model(deriv_flag)
int     deriv_flag;
{
        double  x, yfit;

        x = X;
        yfit = CONST + LINEAR * x;
        if (deriv_flag) {
                if (fCONST)
                        dCONST = 1;
                if (fLINEAR)
                        dLINEAR = x;
        }
        return(yfit);
}
The argument deriv_flag is nonzero when the routine model() must calculate derivatives for the parameters currently being fit. Of course, the routine only need calculate these derivatives if the structure initial indicates they are to be user-provided. If the derivatives are to be user-provided and deriv_flag is set, you still only calculate derivatives if the parameter is currently being fit. In this example, that is the case when fCONST or fLINEAR are nonzero.

Although you could use the definition X for the current value of the independent variable each time you refer to it, the code will be more efficient if it refers to X just once. That is the purpose of the line x = X.