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
 Origin Forum
 Fitting of a function with an integral

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
marwan007 Posted - 05/12/2011 : 1:55:23 PM
origin Ver. and Service Release (Select Help-->About Origin): 8.5.0 G SR1
Operating System: Win 7 Pro 32-bit

Hello,

I've problems with NAG_Library. I want to create a fit function(see originC code)

I wish to fit my funtion to data.By reading the thread http://www.originlab.com/forum/topic.asp?TOPIC_ID=7802 and the linked tutorial on Origin wiki.

I wrote the fowlling Orgin C code. But when I compiled it, the following error mesages comes out:
Linking...
Done!
compiling...
_nlfNewFunction.fit
C:\Users\marwan\Documents\OriginLab\85\User Files\OriginC\NLSF\_nlfNewFunction.fit(102) :Error, cannot convert argument in function call
C:\Users\marwan\Documents\OriginLab\85\User Files\OriginC\NLSF\_nlfNewFunction.fit(102) :Error, general compile error
C:\Users\marwan\Documents\OriginLab\85\User Files\OriginC\NLSF\_nlfNewFunction.fit(69) :Error, error(s) found in compiling function _nlsfNewFunction
Compile Failed!



pragma warning(error : 15618)
#include <origin.h>
#include <data.h>
#include <math.h>
#include <utilities.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.

struct user

{
double a, b, c, d, e, seg, r;



};
static double NAG_CALL f_callback(double x,double a,double b,double c,double e, Nag_User *comm) // x is the independent variable of the integrand
{

struct user *sp = (struct user *)(comm->p);

double aa, bb, cc, dd, ee,segseg, r; // temp variable to accept the parameters in the Nag_User communication struct
aa = sp->a;
bb = sp->b;
dd = sp->d;
cc= sp->c;
ee= sp->e;
segseg=sp->seg;
r = sp->r;
double n=a+(b/x)^2;
double k=(x/(4*pi))*exp(((c/x)^2) - e);
double fi=4*pi*n*r/x;
double A=exp((-4)*pi*k*r/x);
double M=16*s*(n^2+k^2);
double P=((n+1)^2+k^2)*((n+1)*(n+s^2)+k^2);
double Q=(((n^2-1+k^2)*(n^2-s^2+k^2)-(2*k^2)
double R=((n-1)^2+k^2)*((n-1)*(n-s^2)+k^2);
double T=100*(M*A)/(P-Q*A+R*A^2)

return (exp((-1/2)*((r-d)/seg)^2)*T) ;

}

// 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 _nlsfNewFunction(
// Fit Parameter(s):
double a, double b, double c, double d, double e, double seg,
// Independent Variable(s):
double x,
// Dependent Variable(s):
double& y)
{
const double s=2;
// Beginning of editable part


double epsabh = 0.00001, epsrel = 0.0000001, result, abserr;
Integer max_num_subint = 500;
// you may use epsabs and epsrel and this quantity to enhance your desired precision
// when not enough precision encountered

Nag_QuadProgress qp;
static NagError fail;

// the parameters parameterize the integrand can be input to the call_back function
// through the Nag_User communication struct
Nag_User comm;
struct user h;
h.a = a;
h.b = b;
h.c = c;
h.e = e;
h.seg = seg;

h.r = x;
comm.p = (Pointer)&h;

d01smc(f_callback, Nag_UpperSemiInfinite, x, epsabh, epsrel, max_num_subint, &result, &abserr, &qp, &comm, &fail);


// you may want to exam the error by printing out error message, just uncomment the following lines
// if (fail.code != NE_NOERROR)
// printf("%s\n", fail.message);


// For the error other than the following three errors which are due to bad input parameters
// or allocation failure NE_INT_ARG_LT NE_BAD_PARAM NE_ALLOC_FAIL
// You will need to free the memory allocation before calling the integration routine again to
// avoid memory leakage
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 = (1/(seg*sqrt(2*pi)))*result;
// note use log of the integral result as return as the integral result is large,
// you are not necessary to do so

// End of editable part
}

please help me!!
1   L A T E S T    R E P L I E S    (Newest First)
larry_lan Posted - 05/15/2011 : 9:46:43 PM
Hi:

Please search "nag_1d_quad_inf_1" (d01smc) in Origin C help and click the link to download the PDF help file for this NAG function.

You can see from NAG PDF that the specification of f (the callback function) is: double f(double x, Nag_User *comm).

P.S, I also got mis-match parenthesis in this line:

double Q=(((n^2-1+k^2)*(n^2-s^2+k^2)-(2*k^2)

Thanks
Larry

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