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 for Programming
 Forum for Origin C
 User function for Fit Peak in Origin C
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

cyberjuda

Germany
Posts

Posted - 07/01/2009 :  12:45:58 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver.8 and Service Release 4(Select Help-->About Origin):
Operating System: Windows XP Professional

Hello,
I managed to change an example given on the wiki to fit my function (given below) pretty well, but I seem to be unsure about the shape of the peak. Can someone please look at the code and let me know if the function is properly defined by the code. I am using it in the Fitting Function Organiser. My confusion is with the two types of x that I have in the equation. Once inside the integral and one outside. I tried to incorporate it at the end of the code but am not sure if this is the right way to do it. Thanks in advance. :)



#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
{
	double a, b, fitX;  // fitX the independent variable of fitting function
 
};
static double NAG_CALL f_callback(double x, Nag_User *comm)  // x is the independent variable of the integrand
{
 
	struct user *sp = (struct user *)(comm->p);
 
        double aa, bb, fitX, Gas, beta, tau; // temp variable to accept the parameters in the Nag_User communication struct
        aa = sp->a; // a = Frequency Factor, b = Energy in J/mol, fitX = Temperature T inside integral, 
        bb = sp->b; // Gas = Gas constant in J/K mol, beta = Heating Rate, tau = V/S Vacuum constant;
        fitX = sp->fitX;
        Gas = 8.314;
        beta = 19;
        tau = 0.65;
 
        return exp(fitX/(beta*tau))*exp(-bb/(Gas*fitX))*exp((-aa*Gas*fitX*fitX*exp(-bb/(Gas*fitX)))/(beta*bb));
}
 
// 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 _nlsfPWwithparametric(
// Fit Parameter(s):
double a, double b, double c, double d, double y0,
// Independent Variable(s):
double x,
// Dependent Variable(s):
double& y)
{
	// Beginning of editable part
	// Beginning of editable part
	double epsabs = 0.00001, epsrel = 0.0000001, result, abserr;
	double beta, tau;
	beta = 19;
	tau = 0.65;
	Integer max_num_subint = 5000;  
	        // 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 s;
	s.a = a;
	s.b = b;
	s.fitX = x;
	        comm.p = (Pointer)&s;
	 
	d01sjc(f_callback, c, s.fitX, 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);
	}
	 
	 
	y = y0+d*(a/beta)*(exp(-x/(beta*tau)))*result; 
	// End of editable part
}

larry_lan

China
Posts

Posted - 07/03/2009 :  01:01:31 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi:

I think these code is OK. If it doesn't work, please send your data Here then we can have a try.

Thanks
Larry
OriginLab Technical Services

Edited by - larry_lan on 07/03/2009 04:38:38 AM
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