Author |
Topic |
|
ttanhfr
3 Posts |
Posted - 01/28/2013 : 03:23:57 AM
|
Origin Ver. and Service Release (Select Help-->About Origin): OriginPro 8.5.1 Operating System:Windows XP I have a data as follows: x y 695 5306 696 5278 697 5292 698 5476 699 5611 700 5799 701 6557 702 7908 703 10849 704 14896 705 19283 706 22559 707 25163 708 26579 709 27061 710 27802 711 27817 712 27923 713 27809 714 27792 715 27664 716 27817 717 27257 718 27481 719 26872 720 26725 721 25463 722 23203 723 20041 724 16121 725 11754 726 8198 727 6396 728 5420 729 5379 730 5564 731 5403 732 5167
I want to fit data with a function: F2(E)=N2*integral(0,PI){exp(-(x-xc+k*cos(t))^2/2/w^2)*sin(t)dt} where k=11.424 A:peak amplitute xc=E0: centroid peak w: peak width t=theta: recoil angle Could you show me how to create this function in OriginLab. Thank you. http://www.originlab.com/ftp/forum_and_kbase/Images/B.pdf |
|
Penn
China
644 Posts |
Posted - 01/28/2013 : 8:45:27 PM
|
Hi,
You can refer to this tutorial.
Penn |
|
|
ttanhfr
3 Posts |
Posted - 01/31/2013 : 02:06:44 AM
|
Hi, Thank you Penn. Following the tutorial, I create a new function as follows:
#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, angle, v0, c; }; // 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, angle, v0, c; // , angle, v0, c temp variable to accept the parameters in the Nag_User communication struct amp = sp->amp; center = sp->center; width = sp->width; angle = sp->angle; v0=4.8E+6; c=3.0E+8; return amp * exp( -0.5*(x - center + (center * v0/c) * cos(angle))*(x - center + (center * v0/c) * cos(angle))/width/width )*sin(angle); } // 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 _nlsfBoronPeakFitting( // Fit Parameter(s): double y0, double A, double xc, double w, double theta, // Independent Variable(s): double x, // Dependent Variable(s): double& y, // Partial Derivative(s): double& dy_y0, double& dy_A, double& dy_xc, double& dy_w, double& dy_theta) { // 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.amp = A; s.center = xc; s.width = w; s.angle = theta; 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_LowerSemiInfinite, 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 + result; // End of editable part }
The result could not be obtained. Something wrong? Anyone can check it for me. Thank you. |
|
|
|
Topic |
|
|
|