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 for Programming
 LabTalk Forum
 nlsf multi-peak fitting error

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
evanm Posted - 08/30/2004 : 06:05:21 AM
Hello,

I have a LabTalk script that is supposed to perform a Lorentzian fit of a dataset containing 3 side-by-side peaks. The fit works if I use the menu command Analysis->Fit MultiPeaks->Lorentzian, however I want to create a script to perform the fit. The core of my script is:

nlsf.begin();
nlsf.init();
nlsf.func$ = "Lorentz";
nlsf.numReplica = 2;
nlsf.dataBegin = Estarti;
nlsf.dataEnd = Eendi;
nlsf.dataStep = 1;
nlsf.pasteToPlot = 0;
nlsf.fitdata$ = "wks_B"
//nlsf.execute(paranint);

//initialize fitting parameters
nlsf.p1 = y0;
nlsf.p2 = xc1;
nlsf.p3 = w1;
nlsf.p4 = A1;
nlsf.p5 = xc2;
nlsf.p6 = w2;
nlsf.p7 = A2;
nlsf.p8 = xc3;
nlsf.p9 = w3;
nlsf.p10 = A3;

//vary all parameters
for(int p = 1; p <= 10; p++)
nlsf.v$(p) = 1;

nlsf.iterate(100);


However when I run this nlsf.iterate generates this error message...

Error, Variable "w" not declared
Error, general compile error
Error, error(s) found in compiling function _nlsfParameterInitialization

Also, if I uncomment the line "nlsf.execute(paranint);" I get the error a second time.

If a lot of iterations are performed the fit occasionally works, but not all of the time. Does anyone know what else I should be doing here or what is going wrong?

Thank you, Evan.

Origin Version: version 7 SR 0
Operating System: Win 2000pro

4   L A T E S T    R E P L I E S    (Newest First)
easwar Posted - 08/31/2004 : 09:52:20 AM
Hi Evan,

I forgot to mention that I tried the script I posted in 7SR4. I see that you have 7SR0 and on a machine here that has 7SR0 we were able to reproduce your error. I suggest that you apply the free SR4 patch for your 7 installation.

Easwar
OriginLab


evanm Posted - 08/31/2004 : 05:09:53 AM
I also know for sure that the error message is coming from the first nlsf.iterate statement. I know the parameters should be y0, xc1, w1, A1, xc2, w2, A2, xc3, w3, A3 for a Lorentzian fit with 2 replicas. So perhaps the iterate() function is looking for the w parameter. I really don't know. I will try emailing tech then.

Thanks, Evan.

evanm Posted - 08/31/2004 : 05:01:11 AM
Thank you easwar, but it still does not work. I tried to do exactly as you did and imported the multpeaks.dat file. Then I coppied your script in the script window exactly, highlighted it, and then ran it. This is what I got:

nslf.begin();
nlsf.init();
nlsf.func$="lorentz";
nlsf.numreplica=2;
nlsf.databegin=1;
nlsf.dataend=100;
nlsf.datastep=1;
nlsf.pastetoplot=0;
nlsf.fitdata$="multpeaks_B";
nlsf.p1=0;
nlsf.p2=1;
nlsf.p3=1;
nlsf.p4=100;
nlsf.p5=4;
nlsf.p6=1;
nlsf.p7=150;
nlsf.p8=7;
nlsf.p9=1;
nlsf.p10=200;
nlsf.iterate(100);
nlsf.iterate(100);
blsf.iterate(100);
nlsf.end();
Error, Variable "w" not declared
Error, general compile error
Error, error(s) found in compiling function _nlsfParameterInitialization

So the error is still present :( ALso the fit does not appear to work either. The worksheet NLSF1 is created but all of its columns are empty!



easwar Posted - 08/30/2004 : 3:45:47 PM
Hi Evan,

First of all, the auto parameter initialization does not work with replicas. This is because currently auto initialization assumes entire dataset for finding initial parameter values and there is no way to know how to divide up the data into segments for the replicas.

You will notice that when you use the NLSF tool in manual mode, when you set replicas to be different from 0, the Parameter Initialization menu item is greyed out.

Now, for the lorentz function, the default parameter names are xc, w, A etc. But once you turn on replicas, xc, w, A etc are no longer valid, and the names are xc1, w1, xc2, w2 etc. The problem you experience with an error popping up stating w is no declared could be due to you trying to run the auto initialization, which uses w, but w no longer is valid.

I tried the following:
1> imported the sample data file multpeaks.dat from the Samples->Data subfolder under Origin
2> ran the script pasted below to fit the data in the 2nd column which has 3 lorentzian peaks

This worked fine for me without any errors.

If you cannot fix the problem, please send your data and your script to tech@originlab.com

Easwar
OriginLab



nslf.begin();
nlsf.init();
nlsf.func$="lorentz";
nlsf.numreplica=2;
nlsf.databegin=1;
nlsf.dataend=100;
nlsf.datastep=1;
nlsf.pastetoplot=0;
nlsf.fitdata$="multpeaks_B";
nlsf.p1=0;
nlsf.p2=1;
nlsf.p3=1;
nlsf.p4=100;
nlsf.p5=4;
nlsf.p6=1;
nlsf.p7=150;
nlsf.p8=7;
nlsf.p9=1;
nlsf.p10=200;
nlsf.iterate(100);
nlsf.iterate(100);
blsf.iterate(100);
nlsf.end();



Notes: By default, all parameters are set to vary and so I did not set their vary status.
It is a good idea to repeat the nlsf.iterate() lines a few times even if you specify iteration number to be large such as 100. This ensures that the final result is the true converged result


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