Author |
Topic  |
|
wqchen1900
Singapore
3 Posts |
Posted - 04/16/2018 : 03:55:01 AM
|
Origin Ver. and Service Release (Select Help-->About Origin): Origin 9 Operating System: Windows 10
Hi, I have a problem to do integration through NAG with the below code. It successfully compile, but didn't do integration. Can you help to check what may be the problem? Thanks.
#pragma numlittype(push, TRUE) #pragma warning(error : 15618) #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_nag.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 d, g, t1, b, fitX; }; static double NAG_CALL f_callback(double x, Nag_User *comm) { struct user *sp = (struct user *)(comm->p); double bidinE, gapE, width, nonpar, fitX; // temp variable to accept the parameters in the Nag_User communication struct dE = sp->d; gE = sp->g; width = sp->t1; nonpar = sp->b; fitX = sp->fitX; return (2/(exp((fitX-x)/width)+exp(-(fitX-x)/width)))/(1-exp(-2*PI*sqrt(dE/(x-gE))))/(1-nonpar*(x-gE)); } // 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 _nlsfMyIntegFitNAG1( // Fit Parameter(s): double a, double d, double g, double t1, double b, // 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 difficult the integrand the larger max_num_subint should be // For most problems 200 to 500 is adequate and recommended Integer max_num_subint = 500; // 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.d = d; s.g = g; s.t1 = t1; s.b = b; s.fitX = x; comm.p = (Pointer)&s; // 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, g, Nag_UpperSemiInfinite, 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/x)*result; // End of editable part } |
|
wqchen1900
Singapore
3 Posts |
Posted - 04/16/2018 : 2:25:31 PM
|
Can some one help? |
 |
|
yuki_wu
896 Posts |
|
wqchen1900
Singapore
3 Posts |
Posted - 04/17/2018 : 05:00:14 AM
|
Hi, Yuki,
The code was written following the tutorial with some modifications.I only change the integrated function and don't know why it didn't perform the integration and didn't give compile error.
Can you help to test the code in the origin? Do you know what may be the problem? Thanks.
Best regards,
quote: Originally posted by yuki_wu
Hi,
To define an Origin C fitting function which involves an integral, you can take a look at this tutorial at first: https://www.originlab.com/doc/Tutorials/Fitting-Integral-NAG
Regards, Yuki OriginLab
|
 |
|
yuki_wu
896 Posts |
Posted - 04/18/2018 : 01:49:34 AM
|
Hi,
You should double check your fitting model first. I mean if fitX = x, the model will be
Y = (2/e)/(1-exp(-2*PI*sqrt(d/(x-g))))/(1-b*(x-g));
I don’t think this is the integrand function you need.
Regards, Yuki OriginLab
|
 |
|
|
Topic  |
|
|
|