IMSL C Math Library
Return Values from User-Supplied Functions
All values returned by user-supplied functions must be valid real numbers. It is the user’s responsibility to check that the values returned by a user-supplied function do not contain NaN, infinity, or negative infinity values.
In addition to the techniques described below, it is also possible to instruct the IMSL C Numerical Library to return control to the calling program in case an unrecoverable error occurs within a user-supplied function. See function imsl_set_user_fcn_return_flag for a description of this feature.
 
        #include <imsl.h>
        #include <math.h>
 
        void fcn(int, int, float[], float[]);
        int main()
        {
            int m=3, n=1;
            float *result, fx[3];
            float xguess[]={1.0};
            result = imsl_f_nonlin_least_squares(fcn, m, n, IMSL_XGUESS,
                xguess, 0);
            fcn(m, n, result, fx);
            /* Print results */
            imsl_f_write_matrix("The solution is", 1, 1, result, 0);
            imsl_f_write_matrix("The function values are", 1, 3, fx, 0);
        }
 
        void fcn(int m, int n, float x[], float f[])
        {
            int i;
            float y[3] = {2.0, 4.0, 3.0};
            float t[3] = {1.0, 2.0, 3.0};
            for (i=0; i<m; i++)
            {
                /*      check for x=0    
                do not want to return infinity to nonlin_least_squares    */
                if (x[0] == 0.0) {
                    f[i] = 10000.;
                } else {
                    f[i] = t[i]/x[0] - y[i];
                }
            }
        }