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 user data using 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
u@nlo Posted - 01/03/2014 : 12:50:38 AM
Origin Ver.8.5 and Service Release 1 (Select Help-->About Origin):
Operating System: windows7


Can anyone please provide help in code for the above function.
here user data consists of Z and T(Z) values (100 points and above values) remaing all are constant parameters.
I tried with modifying coding of another fun..still i lost my continuity at many stages.

Here is the code i tried with many mistakes.

Can anyone please assist me in this part.

#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 amp, center, width;
 
};
// 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 amp, center, width;    // temp variable to accept the parameters in the Nag_User communication struct
        amp = sp->amp;
        center = sp->center;
        width = sp->width;
 
	return amp * exp( -2*(x - center)*(x - center)/width/width ) / (width*sqrt(PI/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 _nlsfzscan(
// Fit Parameter(s):
double i0, double L, double x0, double l0, double a0, double lmd, double yo, double b,
// Independent Variable(s):
double x,
// Dependent Variable(s):
double& y)
{
	// Beginning of editable part

	L=(1-exp(-a0*l))/a0;
		x'=i0*L*(1+(x/x0)^2);
			y0=1/(sqrt(pi)*x');
	
	
	// 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.amp = A;
	        s.center = xc;
	        s.width = w;
	        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
	d01smc(f_callback, Nag_Infinite, 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 = (y0/b)*result;
	 
	// End of editable part
}


<b><i>U@NLO</i></b>
1   L A T E S T    R E P L I E S    (Newest First)
Sam Fang Posted - 01/10/2014 : 12:39:49 AM
For
z0=pi*w0^2/lmd
, over parameterization exists in w0 and lmd, so here we used z0 as the parameter. You can apply a constraint to get w0 and lmd from z0. The fitting function can be defined as:
---------------------------------------

#include <oc_nag8.h>

struct user   // parameters in the integrand
{
	double q;
 
};
// 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 q;    // temp variable to accept the parameters in the Nag_User communication struct
        q = sp->q;;
 
	return ln(1+q*exp(-x^2));
}

void _nlsfzscan(
// Fit Parameter(s):
double i0, double a0, double l, double b, double z0,
// Independent Variable(s):
double x,
// Dependent Variable(s):
double& y)
{
	// Beginning of editable part
	
	double L,q;
	
	L=(1-exp(-a0*l))/a0;
	q=b*i0*L*(1+(x/z0)^2);
	
	
	// 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.q = q;
	
	comm.p = (Pointer)&s;
	 
	// Perform integration
	// There are 3 kinds of infinite boundary types you can use in Nag infinite integrator
	double bound;
	// Nag_LowerSemiInfinite, Nag_UpperSemiInfinite, Nag_Infinite
	d01smc(f_callback, Nag_Infinite, bound, 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 = 1/sqrt(pi)/q*result;
	 
	
	// End of editable part
}

---------------------------------------

Sam
OriginLab Technical Services

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