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.
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; } return bb; }
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.
//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>
static double NAG_CALL f(int n, double z[], Nag_User *comm) { int *use_comm = (int *)comm->p; double dUserSuppliedFunction; dUserSuppliedFunction = z[0] + z[n-1]; return dUserSuppliedFunction; }
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 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 }
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