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
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Problems with Fitting with Integral using NAG_Libr

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
torstenschwarz Posted - 05/09/2011 : 07:37:27 AM
Origin Ver. and Service Release (Select Help-->About Origin): 8.5.0 G SR1
Operating System: Win 7 Pro 64-bit

Hello,

I've problems with NAG_Library. I want to create this fit function:http://www.originlab.com/ftp/forum_and_kbase/Images/Or85fit.pdf

N and W_0 are fit parameters and a and d are constants.

I used these tutorials:
http://wiki.originlab.com/~originla/howto/index.php?title=Tutorial:Fitting_with_Integral_using_NAG_Library
http://wiki.originlab.com/~originla/howto/index.php?title=Tutorial:Fitting_Integral_Function_with_parametric_limit_using_NAG_Library
http://wiki.originlab.com/~originla/howto/index.php?title=Tutorial:User_Defined_Fitting_Funciton_using_GNU_Scientific_Library

But there are still problems, when I want to compile the fit function:
First problem: Including origin.h (don't know why, he can't find this file).
Can anyone help me?

Thanks.

#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.

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

// 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 _nlsfThomasHopfield(
// Fit Parameter(s):
double N, double W,
// Independent Variable(s):
double x, double r,
// Dependent Variable(s):
double& y)
{
	const double a=1;
	const double d=1;
	// Beginning of editable part
	#include <origin.h>
	#include <oc_nag8.h>
	
	struct user
	{
	 double Nkonz,Wmax,fitX;
	};
	
	static double NAG_CALL f_callback(double r, Nag_User *comm)
	{
	 struct user *sp = (struct user *) (comm->p);
	
	double aa,bb,fitX;
	aa=sp->Nkonz;
	bb=sp->Wmax;
	fitX=sp->fitX;
	
	return (exp(-Wmax*exp(-2fitX/a))-1)*fitX*fitX;
	}
	
	void nlsfnag_integration_fitting
	(
	double W, double N;
	double x,r;
	double& y
	)
	
	{
	 double epsabs=0.0, epsrel=0.0001;
	Integer max_num_subint=400;
	double result, abserr;
	
	NagQuadProgress qp;
	
	static NagError fail;
	
	Nag_User comm;
	struct user s;
	s.Nkonz = N;
	s.Wmax= W;
	s.fitX=r;
	comm.p = (;Pointer); &s;
	
	d01smc(f_callback, Nag_UpperSemiInfinite, r, epsabs, epsrel, max_num_subint, &result, &abserr, &qp, &comm, &fail);
	if (fail.code != NE_INT_ARG_LT && fail.code != NE_BAD_PARAM && fail.code != NE_ALLOC_FAIL)
	        {
	                NAG_FREE(qp.sub_int_beg_pts);
	                NAG_FREE(qp.sub_int_end_pts);
	                NAG_FREE(qp.sub_int_result);
	                NAG_FREE(qp.sub_int_error);
	        }
	y=W*exp(-2.0*d/a)*exp(-x*W*exp(-2.0*d/a))*exp(4.0*PI*result);
	}
	// End of editable part
}
4   L A T E S T    R E P L I E S    (Newest First)
torstenschwarz Posted - 05/10/2011 : 3:01:08 PM
quote:
Originally posted by larry_lan

Hi:

Please define the structures outside the fitting function. Besides, you haven't use any independent variables in your callback function. Are you sure?

I made the code compiled successful, but not sure if the function work. You'd better check the logic by yourself.



I checked your code and it failed when I tried to compile it. There was still a minor mistake in your code. You used in the return function "aa" instead of "a". But "a" is only a constant and it should work anyway.
Can You send me your fit function file, so that I can try myself with your compiled version?

Thanks
Torsten.
tylergalvan Posted - 05/10/2011 : 12:42:52 AM
gosh. very confusing.
larry_lan Posted - 05/09/2011 : 11:29:12 PM
Hi:

Please define the structures outside the fitting function. Besides, you haven't use any independent variables in your callback function. Are you sure?

I made the code compiled successful, but not sure if the function work. You'd better check the logic by yourself.

// This part is outside the fitting function

#pragma numlittype(push, TRUE)
#pragma warning(error : 15618)
#include <origin.h>
#include <oc_nag8.h>

struct user
{
	double Nkonz, Wmax, fitX;
};

static double NAG_CALL f_callback(double r, Nag_User *comm)
{
	struct user *sp = (struct user *) (comm->p);
	
	double aa, bb, fitX;
	aa = sp->Nkonz;
	bb = sp->Wmax;
	fitX = sp->fitX;
	
	r;  // Haven't use r in ths callback
	return (exp(-bb*exp(-2*fitX/aa))-1)*fitX*fitX;
}

// This part is un-editable

void _nlsfThomasHopfield(
// Fit Parameter(s):
double N, double W,
// Independent Variable(s):
double x, double r,
// Dependent Variable(s):
double& y)
{
	const double a=1;
	const double d=1;
	// Beginning of editable part

// This is the function body

	double epsabs=0.0, epsrel=0.0001;
	Integer max_num_subint=400;
	double result, abserr; 
	
	Nag_QuadProgress qp;
	
	static NagError fail;
	
	Nag_User comm;
	struct user s;
	s.Nkonz = N;
	s.Wmax= W;
	s.fitX=r;
	comm.p = (Pointer)&s;
	
	d01smc(f_callback, Nag_UpperSemiInfinite, r, epsabs, epsrel, max_num_subint, &result, &abserr, &qp, &comm, &fail);
	if (fail.code != NE_INT_ARG_LT && fail.code != NE_BAD_PARAM && fail.code != NE_ALLOC_FAIL)
	        {
	                NAG_FREE(qp.sub_int_beg_pts);
	                NAG_FREE(qp.sub_int_end_pts);
	                NAG_FREE(qp.sub_int_result);
	                NAG_FREE(qp.sub_int_error);
	        }
	y=W*exp(-2.0*d/a)*exp(-x*W*exp(-2.0*d/a))*exp(4.0*PI*result);

// This part is un-editable

	// End of editable part
}


Thanks
Larry
eddiecarter Posted - 05/09/2011 : 9:53:43 PM
gosh. i might experience this problem as well. how should we solve this one?

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000