3.142 FAQ858 How to build up a summation fitting function or a double integral fitting funtion?SummationDoubleIntegralFunc
Last Update: 10/12/2017
You can create your userdefined summation or double integral fitting function by LabTalk scripts or Origin C codes, in Tools: Fitting Function Organizer.
summation fitting function
You can define the fitting function with an embedded For loop in the function definition box. Take the following function as an example.
Suppose you define the fitting function in the Function box as follow:
y = sum(x, a, n); //n is a constant, and n=10
Then define the userdefined LabTalk functions sum in the LabTalk Functions Definition and Initializations box as follow:
function double sum(double x, double a, int n)
{
double bb = 0;
for(ii =1; ii<=n; ii++)
{
bb = a * x * x + bb;
}
return bb;
}
double integral fitting function
You can define an Origin C fitting function in which NAG functions are called to perform the integration. Take the following function as an example.
 Click the button next to the Function edit box to open the Code Builder.
 Scroll up to go to line
//add the header file for the NAG functions here.
and add the header file for the NAG functions below this line:
#include <OC_nag.h>
 Define your fitting model.
static double NAG_CALL f(int n, double z[], Nag_User *comm)
{
int *use_comm = (int *)comm>p;
double dUserSuppliedFunction;
dUserSuppliedFunction = z[0] + z[n1];
return dUserSuppliedFunction;
}
 Edit your fitting function.
void _nlsfnag_double_integral_fitting(
// Fit Parameter(s):
double amp,
// Independent Variable(s):
double x,
// Dependent Variable(s):
double& y)
{
// Beginning of editable part
static int use_comm;
int ndim = 2; // the integral dimension
int maxpts = 1000*2; // maximum number of function evaluation
double a[2], b[2];
static NagError fail;
double finval;
int minpts;
double acc, eps;
Nag_User comm;
comm.p = (Pointer)&use_comm; // For communication with usersupplied functions
for (int k=0; k < ndim; ++k) // integration interval
{
a[k] = amp;
b[k] = x;
}
eps = 0.0001; // set the precision
minpts = 0;
d01wcc(ndim, f, a, b, &minpts, maxpts, eps, &finval, &acc, &comm, &fail);
y = finval;
// End of editable part
}
 Click Compile button to compile.
We provide several tutorials of userdefined integral functions. Refer to the corresponding topic for detailed steps if needed:
Keywords: integrate, integral, fitting, Origin C, LabTalk, NAG, summation, double integral
