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
 help need in nonlinear fitting
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

fusswolf

USA
Posts

Posted - 04/18/2006 :  10:55:52 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): 7.0
Operating System:windows 2000
actually this is an integration problem which has been discussed before. but i still need some further help.
our data is the convolution results of two functions. one is a gaussian function as y1=A*exp(-(x/P1)^2) and the other one is a square pusle function as y2={(0,x<-P2/2)(1,-P2/2<x<P2/2),(0,x>P2/2)).here A,P1,P2 are parameters to fit. So,our fitting function looks like y3=y0+integration(y1[x]*y2[t-x])dx. (y0 is only for baseline,t is real variable). But i don't know how to write a piecewised function like y2.
Also the result of the integration can be calculated and it is an error function like: Integrate[exp(-x^2)]dx,with integration limit (-P2/2+t)/P1<x<(P2/2+t)/P1. Similar case has been discussed for only one set of data. But we have more than 100. So i still need a
little bit details about how to do this for many sets of data.

thanks.

zachary_origin

China
Posts

Posted - 04/19/2006 :  07:44:17 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

The convolution can be converted to the fitting functions as follows:


you can define an user-defined function named as "convolute2":

Parameter Names: P1,P2, A, y0
Independent Var: x
Dependent Var: y

the function boby goes like:


//the following lines actually perform a integrate to the function
int nH = 100;//this is the number of steps for integrate
double dH = P2/(double)nH;
double dX;
double dFx = 0;
double dIntegral = 0;
for( int ii = 0 ; ii< nH; ii ++ )
{
dX = x + ii * P2/nH;
dFx = exp( -(dX/P1)^2 );
dIntegrate += dH * dFx;
}
y=y0+A*dIntegral;
//-------------------------------------




Using this function, you can fit one data set through the Advanced Fitting Dialog.

Then you should write another OC function to perform the fitting for every data set.


It can be like this:

void MultiCurveFit()
{
Worksheet wks("Data1");"); //here is the data worksheet name
if(!wks) return;
using NLSF = LabTalk.NLSF;

int nCols = wks.GetNumCols();
Dataset dsFit;
string strName;
for(int ii = 1 ; ii < nCols; ii++) //Col(0) is X
{ //perform fitting for every column
dsFit.Attach( wks, ii );
dsFit.GetName(strName);
NLSF.begin();
NLSF.init();
NLSF.cleanupfitdata();
NLSF.Func$ = "convolute2";
NLSF.fitdata$ = strName;
NLSF.P1=3.0;
NLSF.P2=5.0;
NLSF.P3=2.0;
NLSF.P4=1.0;
NLSF.fit(10); //iterating for 10 times
NLSF.end(1);
LT_execute("rescale()");
dsFit.Detach();
}
}
//---------------------



when it iterates for 10 times, the result is good:


Parameter Value Error
----------------------------------------
P1 4.16934 0.07113
P2 1.46474 0.24861
A 3.09749 0.45967
y0 0.29562 0.00346
----------------------------------------





(If you found you cannot use Origin C in NLSF dialog, please select menu: Help->About Origin to open the dialog box. Check if the version is Origin 7 SR0 or Origin 7 SR1. If so, you need to update your Origin into the higher version (maybe SR4) first. )





Zachary
OriginLab, GZ office.




quote:

Origin Version (Select Help-->About Origin): 7.0
Operating System:windows 2000
actually this is an integration problem which has been discussed before. but i still need some further help.
our data is the convolution results of two functions. one is a gaussian function as y1=A*exp(-(x/P1)^2) and the other one is a square pusle function as y2={(0,x<-P2/2)(1,-P2/2<x<P2/2),(0,x>P2/2)).here A,P1,P2 are parameters to fit. So,our fitting function looks like y3=y0+integration(y1[x]*y2[t-x])dx. (y0 is only for baseline,t is real variable). But i don't know how to write a piecewised function like y2.
Also the result of the integration can be calculated and it is an error function like: Integrate[exp(-x^2)]dx,with integration limit (-P2/2+t)/P1<x<(P2/2+t)/P1. Similar case has been discussed for only one set of data. But we have more than 100. So i still need a
little bit details about how to do this for many sets of data.

thanks.




Edited by - zachary_origin on 04/19/2006 07:47:48 AM

Edited by - zachary_origin on 04/19/2006 07:53:17 AM

Edited by - zachary_origin on 04/30/2006 04:14:09 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