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
 fit to Integral function

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
tongwei Posted - 10/16/2010 : 11:17:38 AM
Origin Ver.8.1 and Service Release SR3(Select Help-->About Origin):
Operating System:Windows 7 pro(64)


I wish to fit the above 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...
_nlfnag_integration_fitting.fit
D:\WeiTong\tools\Origin81func\OriginC\NLSF\_nlfnag_integration_fitting.fit(17) :Error, Function argument x is not used inside the function body
D:\WeiTong\tools\Origin81func\OriginC\NLSF\_nlfnag_integration_fitting.fit(16) :Error, error(s) found in compiling function f_callback
Compile Failed!"


Please help on this fitting. Thanks.

Origin C code


#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.
struct user // parameters in the integrand
{
double thR,fitX;

};
// Function supplied by user, return the value of the integrand at a given x.
static double NAG_CALL f_callback(double x, Nag_User *comm)
{
struct user *sp = (struct user *)(comm->p);

double thR,fitX; // temp variable to accept the parameters in the Nag_User communication struct
thR = sp->thR;
fitX = sp->fitX;

return fitX^5/(exp(fitX)-1)/(1-exp(-fitX));
}


// 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 _nlsfnag_integration_fitting(
// Fit Parameter(s):
double r0, double A, double B, double thetaR,
// Independent Variable(s):
double x,
// Dependent Variable(s):
double& y)
{
// Beginning of editable part
double epsabs = 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

// Parameters passed to integrand by Nag_User communication struct
Nag_User comm;
struct user s;
s.thR = thetaR;
s.fitX = x;
comm.p = (Pointer)&s;

d01sjc(f_callback, 0, thetaR/x, epsabs, 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);
}

// Calculate the fitted value
y=r0+A*x^2+B*x^5*result

// End of editable part
}
2   L A T E S T    R E P L I E S    (Newest First)
tongwei Posted - 10/18/2010 : 02:36:20 AM
Where or How to use the x? (Actually I used x in some places) Please indicate it exactly.
Thanks.

WT

quote:
Originally posted by larry_lan

You need to use the parameter, x, which you have defined, in the callback function, static double NAG_CALL f_callback.

Thanks
Larry

larry_lan Posted - 10/17/2010 : 9:31:37 PM
You need to use the parameter, x, which you have defined, in the callback function, static double NAG_CALL f_callback.

Thanks
Larry

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