3.142 FAQ-858 How to build up a summation fitting function or a double integral fitting funtion?
Last Update: 10/12/2017
You can create your user-defined 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 user-defined 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;
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:
- Define your fitting model.
static double NAG_CALL f(int n, double z, Nag_User *comm)
int *use_comm = (int *)comm->p;
dUserSuppliedFunction = z + z[n-1];
- Edit your fitting function.
// Fit Parameter(s):
// Independent Variable(s):
// Dependent Variable(s):
// 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, b;
static NagError fail;
double acc, eps;
comm.p = (Pointer)&use_comm; // For communication with user-supplied 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 user-defined integral functions. Refer to the corresponding topic for detailed steps if needed:
Keywords: integrate, integral, fitting, Origin C, LabTalk, NAG, summation, double integral