Hi Hisham,
Let me take a simple example:
1. I will fit the following model as illustrated:
2. Press F9 to open the Fitting Function Organizer dialog and then create a new function as below:
3. Click the button beside the Function box to open the code builder
4. Add the header file for the NAG functions.
#include <OC_nag.h>
5.Define your fitting model.
static double NAG_CALL f(Integer n, double z[], Nag_User *comm)
{
double tmp_pwr;
tmp_pwr = z[0]+z[1];
return tmp_pwr;
}
6.Edit your fitting function.
void _nlsfnag_integration_fitting(
// Fit Parameter(s):
double amp,
// Independent Variable(s):
double x,
// Dependent Variable(s):
double& y)
{
// Beginning of editable part
Integer ndim = 2; // the integral dimension
Integer maxpts = 1000*2; // maximum number of function evaluation
double a[4], b[4];
Integer k;
static NagError fail;
double finval;
Integer minpts;
double acc, eps;
Nag_User comm;
for (k=0; k < 2; ++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
}
7. Click Compile button, and then Return to Dialog
8. Click Save button
9. Click Simulate button to check the fitting function
Hope it helps.
Regards,
Yuki
OriginLab