OriginPro 0.0.0G (32-bit)
Windows XP
Hi everyone, I'm having problems with fitting using an integral. My code is as following
#pragma numlittype(push, TRUE)
#pragma warning(error : 15618)
#include <origin.h>
#include <oc_nag8.h>
struct user // parameters in the integrand
{
double c, dE, p, E1, E;
};
// 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 dE, p, E1, E, b;
p = sp->p;
E1 = sp->E1;
dE = sp->dE;
E = sp->E;
double EE = E-x-E1;
double arg = EE*EE/(dE*dE*2.0)-p*ln(E-E1);
return (arg < 30) ? exp(-arg) : 0.0;
}
double epsabs = 1E-12, epsrel = 0.00001;
epsrel = ebs;
Integer max_num_subint = 500;
double result, abserr;
Nag_QuadProgress qp;
static NagError fail;
Nag_User comm;
struct user s;
//s.c = c;
s.dE = dE;
s.p = p;
s.E1 = E1;
s.E = x;
comm.p = (Pointer)&s;
if (x > E1)
d01smc(f_callback, Nag_Infinite, Nag_Infinite, epsabs, epsrel, max_num_subint, &result, &abserr, &qp, &comm, &fail);
else
result = 0.0;
if (fail.code != NE_NOERROR)
{
result = 0.0;
printf("%s\n", fail.message);
}
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);
}
y = b + c*result;
When I simulate the function (manage fit functions, F9), the function looks quite good, but for some parameters it got "holes" in it. This means, the numerical integration fails with the error "NE_QUAD_NO_CONV: The integral is probably divergent or slowly convergent." I'm pretty sure that it's not divergent, so are there parameters, with which I can give the calculation more time or something like this?
Thanks for helping.