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
 Defined f=Voigt function +nonconstant background

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
z_b Posted - 08/06/2009 : 4:25:10 PM
Hi,everybody.

I have a problem while modifying the built-in voigt function.

The voigt function in Origin 8 assumes a constant background,corresponding to 'y0' in the equation. Now, i want to the change the background from 'y0' to 'C*x^2+B*x+y0',where B,C are fitted parameters, x independent variable. This means two terms---C*x^2 and B*x are added to the original equation. I have tried two methods but failed to get the curve corresponding to my defined function. Below are about the mehtods i tried and the relevant problems encountered:
Method 1: quote the bulit-in function voigt5(x,y0,xc,A,wG,wL)
e.g. select the function form as 'Y-script'and write the function in the box as:temp=nlfxVoigt5(x,y0,xc,A,wG,wL);y=temp+B*x+C*x*x,errors come out to be 'Error: NLFXVOIGT5(X,Y0,XC,A,WG,WL)
LabTalk expression error: 1600' after running the simulate. Changing the function form to 'expression' can not solve the problem.

Method 2: bulid codes in Origin C
The approximation of voigt function like pseudo-voigt function (psdvoigt1 adn psdvoigt2 in Origin8) can easily be modified through the function of 'expression' or 'Y-script', but voigt function can not be successfully modifed as the integration can not be accomplished thourgh just writing 'integ' in the function box.I referred to the tutorial regarding the integration algorithm in Origin (available from http://wiki.originlab.com/~originla/howto/index.php?title=Tutorial:Fitting_with_Piecewise_Functions), and wrote a program corresponding to my defined function. The compiling succeeded in the cold bulider, but the simulated curve appeared as a horizontally straight line, which moves along with the adjustment of y0 value. I have tried to find the solution to the problems but.....
Anyone can kindly give me some help by leaving your suggestion here or emailing to my mailbox---woaijiaoda@hotmail.com? Thanks a lot.
Below is the code written in the code builder:

#pragma warning(error : 15618)
#include <origin.h>


#include <oc_nag8.h>
#define NAG_FREE(X) x04bdc((Pointer *)&(X))

struct user // parameters in the integrand
{
double center, widthG,widthL,xx;
};

static double NAG_CALL f_callback(double t, Nag_User *comm)
{
struct user *sp = (struct user *)(comm->p);
double amp, center, widthG,widthL,xx; // temp variable to accept the parameters in the Nag_User communication struct
center = sp->center;
widthG = sp->widthG;
widthL = sp->widthL;
xx = sp->xx;
return exp( -t*t ) / (ln(2)*(widthL/widthG)*(widthL/widthG)+(2*sqrt(ln(2))*(xx-center)/widthG-t)*(2*sqrt(ln(2))*(xx-center)/widthG-t));
}

//----------------------------------------------------------
//
void _nlsfVoigt1(
// Fit Parameter(s):
double A, double y0, double wL, double wG, double xc,double B,double C,
// Independent Variable(s):
double x,
// Dependent Variable(s):
double& y)
{

double epsabs = 0.0, epsrel = 0.0001;

Integer max_num_subint = 200;
double result, abserr;

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.center = xc;
s.widthG = wG;
s.widthL = wL;
s.xx = x;
comm.p = (Pointer)&s;
// Perform integration
d01smc(f_callback, Nag_LowerSemiInfinite, Nag_UpperSemiInfinite,epsabs, epsrel, max_num_subint, &result, &abserr, &qp, &comm, &fail);

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*x+C*x*x+A*2*(ln(2)*wL/(wG*wG*PI*sqrt(PI)))*result;





// End of editable part
}
1   L A T E S T    R E P L I E S    (Newest First)
larry_lan Posted - 08/06/2009 : 11:10:52 PM
Hi:

You can use the nlfxFuncName mechanism to call built-in functions in an Origin C fitting function. For exmaple, define the function like:

Parameter Name: y0, xc, A, wG, wL, B, C
Function Form: Origin C
Function:
y = B*x + C*x*x + nlfxVoigt5(x, y0, xc, A, wG, wL);
y0; xc; A; wG; wL;

Note that you need to list all of the parameters in your function body (y0; xc; A; wG; wL;) to make compile success. Many users cannot catch this, so we will fix this issue later.

Then I initialize the parameters as below:
xc = peak_pos(x_y_curve, &wG, &y0, &A);
wL = wG;
B=0.1;
C=0.01;

So, the function should looks like:



I test in some sample data and it works well. Would you please take a try and give us feedback?

Thanks
Larry
OriginLab Technical Services

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