The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Problem using NAG function in NLSF
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

gpoon

USA
Posts

Posted - 08/26/2009 :  8:31:44 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. 8.5 and Service Release (Select Help-->About Origin): SR5
Operating System: Windows XP

I am trying to use NLSF to fit an ordinary differential equation using the NAG functions d02pvc and d02pdc in Origin C. I did a test-drive in code-builder and got it to work, so when I gave it a try it in NLSF as follows (where t and d are the independent and dependent variable, respectively):

#pragma warning(error : 15618)
#include <origin.h>
// Add your special include files here.
// For example, if you want to fit with functions from the NAG library,
// add the header file for the NAG functions here.
#include <OC_nag8.h>

// Add code here for other Origin C functions that you want to define in this file,
// and access in your fitting function.

#define NEQ 1 // number of differential equations

struct user // parameters in the differential equations
{
double k, rt; // lowercase to avoid conflict with parameters in NLSF
};

// In addition, by Nag_User struct you can also pass in the parameters for the system
static void NAG_CALL f_callback(Integer neq, double t, double y[], double yp[], Nag_User *comm)
{
struct user *sp = (struct user *)(comm->p);

double k, rt; // temp variable
k = sp->k;
rt = sp->rt;

yp[0] = (y[0] - rt)/(2*y[0] - rt - t - k);
}

// You can access C functions defined in other files, if those files are loaded and compiled
// in your workspace, and the functions have been prototyped in a header file that you have
// included above.

// You can access NLSF object methods and properties directly in your function code.

// You should follow C-language syntax in defining your function.
// For instance, if your parameter name is P1, you cannot use p1 in your function code.
// When using fractions, remember that integer division such as 1/2 is equal to 0, and not 0.5
// Use 0.5 or 1/2.0 to get the correct value.

// For more information and examples, please refer to the "User-Defined Fitting Function"
// section of the Origin Help file.

//----------------------------------------------------------
//
void _nlsfITC11binding(
// Fit Parameter(s):
double Rt, double K,
// Independent Variable(s):
double Lt,
// Dependent Variable(s):
double& d)
{
// Beginning of editable part
Integer neq;
Nag_RK_method method;
double hstart, tstart, tend, tnow, tol;
double thres[NEQ], ynow[NEQ], ygot[NEQ], ypnow[NEQ], ymax[NEQ], ypgot[NEQ], ystart[NEQ];
Nag_ErrorAssess errass;
Nag_ODE_RK opt;
static NagError fail;

// Parameters passed to integrand by Nag_User communication struct
Nag_User comm;
struct user s;
s.k = K; // the parameters of the differential equation systems is passed through this Nag_User communication struct
s.rt = Rt;
comm.p = (Pointer)&s; // you can define your own parametrized differential equation system through this way

/* Set initial conditions and input for d02pvc */
neq = NEQ; // number of differential equations
tstart = 1e-10; // span of the time interval (the independant variable) for the solution
tend = t;
ystart[0] = 0; // initial values
thres[0] = 1.0e-9;
errass = Nag_ErrorAssess_off;
hstart = 0; // 0 value means first step size automatic
method = Nag_RK_7_8; // choose 2_3, 4_5, or 7_8
tol = 1.0e-9;

d02pvc(neq, tstart, ystart, tend, tol, thres, method, Nag_RK_onestep, errass, hstart, &opt, NAGERR_DEFAULT); // setup function need to be called to call the solver d02pcc
do
{
d02pdc(neq, f_callback, &tnow, ynow, ypnow, &opt, &comm, NAGERR_DEFAULT);//&fail);
} while (tnow<tend);

d = ypnow[0];
d02ppc(&opt); // need to call this to free some internal memory used by NAG
// End of editable part
}

It gives me these errors in my NAG_CALL f_callback function:

Error, Function argument neq is not used inside the function body
Error, Function argument y is not used inside the function body
Error, Function argument yp is not used inside the function body
Error, error(s) found in compiling function f_callback

I don't understand what my mistake is. neq is required for f_callback according to the NAG manual and I am using y and yp in the function body. I am particularly confused because all of this works outside NLSF. I'd appreciate any insight, and I apologize for the long code!

Thanks in advance,
Gregory

larry_lan

China
Posts

Posted - 08/31/2009 :  05:21:50 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Gregory:

Please check your email for this issue.

Larry
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000