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
 Origin Forum
 integration fitting with parameter in bound
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

edwardclhuang

Taiwan
9 Posts

Posted - 11/24/2011 :  4:53:29 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 8, SR4
Operating System:Win7 64 bit

Dear Sir

After reading the tutorials of NAG, I still have problems in the fitting with integration because I have a fitting parameter in the upper bound. Please see the attached function. I have tried to write the fitting function with NAG as following.


--------------------------------------------------------------------
#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 thetaD;

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

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

return (thetaD/x)^4*exp(thetaD/x)/((exp(thetaD/x)-1)^2);
}


// 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 _nlsfDebyeTermandlectronic(
// Fit Parameter(s):
double A0, double TD,
// Independent Variable(s):
double x,
// Dependent Variable(s):
double& y)
{
// Beginning of editable part


// Through the absolute accuracy epsabs, relative accuracy epsrel and max_num_subint you can
// control the precision of the integration you need
// if epsrel is set negative, the absolute accuracy will be used.
// Similarly, you can control only relative accuracy by set the epsabs negative
double epsabs = 0.0, epsrel = 0.0001;

// The max number of sub-intervals needed to evaluate the function in the integral
// The more diffcult the integrand the larger max_num_subint should be
// For most problems 200 to 500 is adequate and recommmended
Integer max_num_subint = 200;

// Result keeps the approximate integral value returned by the algorithm
// abserr is an estimate of the error which should be an upper bound for the |I - result|
// where I is the integral value
double result, abserr;

// The structure of type Nag_QuadProgress,
// it contains pointers allocated memory internally with max_num_subint elements
Nag_QuadProgress qp;

// The NAG error parameter (structure)
static NagError fail;

// Parameters passed to integrand by Nag_User communication struct
Nag_User comm;
struct user s;
s.thetaD = TD;
comm.p = (Pointer)&s;

// Perform integration
// There are 3 kinds of infinite boundary types you can use in Nag infinite integrator
// Nag_LowerSemiInfinite, Nag_UpperSemiInfinite, Nag_Infinite
d01sjc(f_callback, 0, TD/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 valu
y=A0*x+9*3*8.3145*(x/TD)^3*result
// End of editable part
}
--------------------------------------------------------------------
Of course I can not compile this successfully. Because, as in the bold part, I use "double thetaD/x" which is definitely wrong. However in my integration, the formula continuously integrate until a converge value and with choosing a proper TD. One of your engineer taught me I may try to replace thetaD/x by x', but in this case I may not know A0, another fitting parameter, and that's not what I want.

Please help me solve the problem. Thanks so much for your help.

Sam Fang

293 Posts

Posted - 11/28/2011 :  04:54:35 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Can you show us the full form of your fitting function? It may help us understand your question better.

Thanks.

Sam
OriginLab Technical Services
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