Author 
Topic 

Piasecki
Poland
Posts 
Posted  01/14/2022 : 08:25:58 AM

Origin Ver. and Service Release (Select Help>About Origin): Operating System: Origin 2022Pro Sr1 9.9.0.225 (Academic), Win 10
Concerning the Fit Convolution appl.: is it possible to add to the fitted function (e.g. Gaussian + Lorenzian) the condition of some cut off, e.g. f(x) = 0 for x < 0? Of course, this condition should not apply to the signal (resolution function), nor to the data. 

YimingChen
995 Posts 

Piasecki
Poland
Posts 
Posted  01/14/2022 : 11:57:38 AM

Thank you, but this I know. Unfortunately, I don't know nor C language, neither LabTalk. I know that e.g. for the Gaussian + Lorentzian the function is defined as: f(x) = A*exp( (4*ln(2)*(xxc)^2)/w1^2 )*(1Sign(xxc))/2.0 + A*(w2^2/(4*(xxc)^2 + w2^2))*( 1+Sign(xxc) )/2.0
Could you please tell me how to modify this expression by introducing the cut f(x) = 0 for x < 0 or more generally for x < xcut ?



YimingChen
995 Posts 
Posted  01/14/2022 : 3:35:25 PM

OK, here is the way to go: 1. Launch the Fit Convolution app, and make the settings as shown below and click Save as... to save the fitting function to myConv. Here we only declare the func(A, xc, w1, w2, x) and we will define it later.
2. Close the app, choose from menu Tools:Fitting function builder..., choose Edit a Userdefined Function, select myConv. Keep click Next button until the Origin C Fitting Function page. Click the button to open Code Builder.
3. Add the code below to the fitting function file. Click Compile button, then click Return to Dialog.
double func(double A, double xc, double w1, double w2, double x) {
if (x < 0) {
return 0;
} else {
return A*exp( (4*ln(2)*(xxc)^2)/w1^2 )*(1Sign(xxc))/2.0 + A*(w2^2/(4*(xxc)^2 + w2^2))*( 1+Sign(xxc) )/2.0;
}
}
4. Click Finish button. Then the fitting function it built. 


YimingChen
995 Posts 
Posted  01/14/2022 : 3:43:30 PM

To fit the data, select col(B) and go to menu Analysis>Fitting>Nonlinear Curve Fit... Pick the fitting function myConv, and run the fit.
I attached the fitting function here.
https://my.originlab.com/ftp/forum_and_kbase/Images/myConv.FDF
James 
Edited by  YimingChen on 01/14/2022 3:45:27 PM 


Piasecki
Poland
Posts 
Posted  01/15/2022 : 04:08:13 AM

Thanks a lot, but this is a different situation than in my case, as here the data are evidently cut at some X value, so you can find the appropriate fitting function f(x). In my case, the situation is different: the cut is certainly present because of the conservation energy law, so all part of the observed distribution to the left of the cut is due to the resolution effects, thus it cannot be seen in the solution, i.e. in the fitting function.
Somehow I cannot find here the way of attaching the figure nor data. I can send them to you if you tell me how.
Eryk 


Piasecki
Poland
Posts 

Piasecki
Poland
Posts 
Posted  01/15/2022 : 12:19:42 PM

Hi, Thanks a lot for your recipe! I tried to follow it, but the compilation failed and I am unable to find the error. I would like to send you the printscreen, but I don't know how to attach the file. Help, pls.
Best regards Eryk 


Piasecki
Poland
Posts 
Posted  01/17/2022 : 12:57:39 AM

Here is the prntscr



YimingChen
995 Posts 
Posted  01/17/2022 : 09:07:22 AM

For the compiling error, you need to define the function func() outside _nlsfmyConv(). Thanks.
James 


Piasecki
Poland
Posts 
Posted  01/17/2022 : 09:58:03 AM

I believe I did it many times.
If "add the code below the fitting function file" means: below the CONVOLUTION( func(A, xc, w1, w2, x), h(x) )
then I did it already many times, with the same error.
If you mean anything else, please explain precisely what you mean by "defining the function func() outside _nlsfmyConv().
Thank you. Eryk 


YimingChen
995 Posts 
Posted  01/17/2022 : 10:30:36 AM

Right now your func() is defined within _nlsfmyConv() function. Can you move the function before the FitConvolutionModel(ARGS2) function as I already showed in the figure?
James 


Piasecki
Poland
Posts 
Posted  01/17/2022 : 11:07:14 AM

Thanks, apparently now it is compiled, but after Return to Dialog cannot click the Finish button, since it is shadowed (see attachment).
What should I do? Eryk 


YimingChen
995 Posts 
Posted  01/17/2022 : 11:18:12 AM

Click Next button until the Finish button is enabled.



Piasecki
Poland
Posts 
Posted  01/17/2022 : 11:27:36 AM

Should I put initial values before compilation? 


YimingChen
995 Posts 
Posted  01/17/2022 : 11:58:17 AM

It shouldn't matter when you set the initial values.



Piasecki
Poland
Posts 
Posted  01/17/2022 : 12:04:28 PM

Great. Unfortunately, I don't see any reaction of the initial distribution (in red) on the parameter setting. Should I? I am asking this since for the moment the iterations cannot result in finding solution, probably by the improper initial parameters setting.
E.



YimingChen
995 Posts 
Posted  01/17/2022 : 2:03:12 PM

In the NLFit dialog, you can select Fitted Curves in the left panel, and in the right panel, set X data Type to same as Input Data. See if it helps.
Otherwise, you can try different initial parameters.
James 


Piasecki
Poland
Posts 
Posted  01/17/2022 : 4:23:34 PM

If I understand what you have in mind, I presume that"Fitted curves" on the left panel ARE selected (see attachment), however I don't know where is the 2nd panel.
Eryk 


YimingChen
995 Posts 
Posted  01/17/2022 : 4:34:46 PM

This is what I meant



Piasecki
Poland
Posts 
Posted  01/17/2022 : 5:12:17 PM

Yes, it partly helps, at least one can see some peak (see att.), but it still doesn't react on the parameter's changes. Eg. here initial xc = 2, but on the plot it is at 12 and is there frozen....
Eryk 


YimingChen
995 Posts 

Piasecki
Poland
Posts 
Posted  01/18/2022 : 10:55:53 AM

Yes, as always (see attachment)
Eryk 


Piasecki
Poland
Posts 

Piasecki
Poland
Posts 

Piasecki
Poland
Posts 
Posted  01/19/2022 : 2:40:34 PM

Unfortunately, my attempts are not successful, the iterations finish without converging. Perhaps the initial parameter values are bad, or the function is not good. Unfortunately, the visualization of the function with initial parameters (the red line in the figure above) is in complete disagreement with the parameters. Anybody knows why???
Eryk 
Edited by  Piasecki on 01/19/2022 2:52:26 PM 



Topic 
