I have written the program and compiled it. The compilation was successful. But I could not do the fitting using the function. Can anyone tell what is the problem? Thank you very much. ps: The function is given the end as a image.
Define the Function Press F9 to open the Fitting Function Organizer and then create a new Category named FittingWithIntegral. Define a new fitting function nag_integration_fitting in the new category as follow:
Function Name: nag_integration_fitting Function Type: User-Defined Independent Variables: x Dependent Variables: y Parameter Names: a Function Form: Origin C Function: Click the button (icon) beside the Function box to open the code builder and define and compile and save the fitting function as follows: #include <origin.h> // Add your special include files here. // For example, if you want to fit with functions from the NAG library, // add the header file for the NAG functions here. #include <oc_nag8.h>
// Add code here for other Origin C functions that you want to define in this file, // and access in your fitting function.
struct user // parameters in the integrand { double cons;
}; // Function supplied by user, return the value of the integrand at a given x. static double NAG_CALL f_callback(double x, Nag_User *comm) { struct user *sp = (struct user *)(comm->p);
double cons; // temp variable to accept the parameters in the Nag_User communication struct cons = sp->cons; return (x*x*x*x*exp(x))/((exp(x)-1)*(exp(x)-1));
}
// You can access C functions defined in other files, if those files are loaded and compiled // in your workspace, and the functions have been prototyped in a header file that you have // included above.
// You can access NLSF object methods and properties directly in your function code.
// You should follow C-language syntax in defining your function. // For instance, if your parameter name is P1, you cannot use p1 in your function code. // When using fractions, remember that integer division such as 1/2 is equal to 0, and not 0.5 // Use 0.5 or 1/2.0 to get the correct value.
// For more information and examples, please refer to the "User-Defined Fitting Function" // section of the Origin Help file.
//---------------------------------------------------------- // void _nlsfnag_integration_fitting( // Fit Parameter(s): double a, // Independent Variable(s): double x, // Dependent Variable(s): double& y) { // Beginning of editable part
// Through the absolute accuracy epsabs, relative accuracy epsrel and max_num_subint you can // control the precision of the integration you need // if epsrel is set negative, the absolute accuracy will be used. // Similarly, you can control only relative accuracy by set the epsabs negative double epsabs = 0.0, epsrel = 0.0001;
// The max number of sub-intervals needed to evaluate the function in the integral // The more diffcult the integrand the larger max_num_subint should be // For most problems 200 to 500 is adequate and recommmended Integer max_num_subint = 300;
// Result keeps the approximate integral value returned by the algorithm // abserr is an estimate of the error which should be an upper bound for the |I - result| // where I is the integral value double result, abserr;
// The structure of type Nag_QuadProgress, // it contains pointers allocated memory internally with max_num_subint elements Nag_QuadProgress qp;
// The NAG error parameter (structure) static NagError fail;
// Parameters passed to integrand by Nag_User communication struct Nag_User comm; struct user s; s.cons = a;
// Perform integration // There are 3 kinds of infinite boundary types you can use in Nag infinite integrator // Nag_LowerSemiInfinite, Nag_UpperSemiInfinite, Nag_Infinite d01smc(f_callback, 0, 444/x, epsabs, epsrel, max_num_subint, &result, &abserr, &qp, &comm, &fail);
// you may want to exam the error by printing out error message, just uncomment the following lines // if (fail.code != NE_NOERROR) // printf("%s\n", fail.message);
// For the error other than the following three errors which are due to bad input parameters // or allocation failure NE_INT_ARG_LT NE_BAD_PARAM NE_ALLOC_FAIL // You will need to free the memory allocation before calling the integration routine again to avoid memory leakage if (fail.code != NE_INT_ARG_LT && fail.code != NE_BAD_PARAM && fail.code != NE_ALLOC_FAIL) { NAG_FREE(qp.sub_int_beg_pts); NAG_FREE(qp.sub_int_end_pts); NAG_FREE(qp.sub_int_result); NAG_FREE(qp.sub_int_error); }
// Calculate the fitted value y = a*5.75*100000*(x/444)*(x/444)*(x/444)*result;