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 for Programming
 LabTalk Forum
 Hello
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

stra11an

USA
7 Posts

Posted - 05/15/2001 :  03:13:30 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hello,
please help me. This is a problem I can´t solve. I have 30 to 50 graphs in a project and as many data worksheets with four columns. Every graph has only one layer and just one curve. I need a script that that will perform a nonlinear square fit on each graph. First column (x-axes) from the worksheet should be set independent and the fourth column (y-axes) should be dependent. I have a custom buit function with four parameters called A, B, G and n and that works. They need to be initialized to 1,1,200 and 1 respectively.
I tryed numerous combinations with a sample script that should work in principle if someone could fill in the blanks for me i.e. type correct sintax.

doc –e D
{ nlsf.func$=´´name´´;
nlsf.fitData$=????; (it should be 4th col from data worksheet)
nlsf.x$=????; (it should be 1st col from data worksheet)
nlsf.xmode=0:;
nlsf.pn=????; (A=1,B=1,G=200,n=1)
nlsf.wType=2;
nlsf.fit(100);
nlsf.pasteToPlot=1;
clr; };

Thanks in advance.
Strahinja Stojadinovic
Kent State University


Edited by - strahinja on 05/15/2001 03:17:08

Edited by - strahinja on 05/15/2001 03:18:17

Edited by - strahinja on 05/15/2001 03:18:54

rtoomey

USA
184 Posts

Posted - 05/15/2001 :  3:58:56 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply

Here's an example script you might consider trying (after amending it):




doc -e W // W is for each worksheet which is what you want to do
{
%A=%H; // store active window name
nlsf.init(); // initialize the fitter
nlsf.func$=MyLine; // initialize the function to be used
nlsf.p1=0.1; // initialize the parameter values
nlsf.p2=0.1;
nlsf.fitData$=%(%A,3); // initialize the dependent dataset
layer -a; // rescale the graph when it comes up
nlsf.wType=2; // statistical weighting
nlsf.fit(100); // 100 iterations
nlsf.xmode=0; // use same X as fit data
%A!wks.col$(%A!wks.ncols).name$="FitData"; // rename fit data column to "FitData"
};



Note 1: Anything in red must be tailored to meet your needs.



Note 2: The function must be defined in the fitter with the Same X as Fitting Data radio button selected in Scripts => After Fit. To get to this window, make sure you are in the "advanced" mode of the fitter. To get to the advanced mode, click the More button. If you don't see a More button (and instead see a Basic Mode button), you are in the advanced mode already.



Note 3: Initializing the parameters using nlsf.pn must be done in the same exact order as they are defined in your function in the Parameter Names text box. In your case, that might be as follows (assuming A,B,G,n is how you ordered the parameter names in the text box):



nlsf.p1=1; // initialize A
nlsf.p2=1; // initialize B
nlsf.p3=200; // initialize G
nlsf.p4=1; // initialize n


Go to Top of Page

stra11an

USA
7 Posts

Posted - 05/16/2001 :  10:56:15 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
thanks rtoomey,
it works great, if you ever happen to be in Kent OH, I'll buy you lunch.
Strahinja
Go to Top of Page

stra11an

USA
7 Posts

Posted - 05/16/2001 :  4:30:43 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
There is one problem, however!
nlsf.pasteToPlot=1; doesn't seem to work.
When I typed echo=1; two errors showed
Error:QuitFit and
Error:EndIterate
The fitted curve was pasted to the graph and it looked very nice.
By the way how do I paste parameters into a worksheet?
Thanks.
Go to Top of Page

rtoomey

USA
184 Posts

Posted - 05/17/2001 :  12:30:42 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The property, nlsf.pastetoplot, is actually just a switch which tells the fitter whether or not you want the parameters pasted to the plot upon completion of the fit. The parameters don't actually get pasted to the plot until you click the Done button on the Fitting Session page of the fitter. In LabTalk terms, this is the equivalent of executing the nlsf.end() method. To fully implement this, add the following lines to your script:

  1. Add nlsf.begin(); immediately after nlsf.init();.
  2. Add nlsf.end(); immediately prior to the closing curly brace }.


In addition to this, you have two options:



1) You can continue to use nlsf.pastetoplot=1; in your script.

or

2) You can enable the Paste Parameters to Plot check box for that function (inside the fitter) and save the change to the function's definition file. Note: To save a function, select Function:Edit and click the Save button. Saving this change to the function will force the fitter to output its results to the plot for ALL future fits.



Finally, your best bet for viewing the parameters in a worksheet would be to click the Param. Worksheet button on the Results page (Action:Results) in the fitter. To duplicate this action through script, you must use the run.section() method to run the ParaConf section of the file called OFIT.OGS. In doing so, you must also pass the script the worksheet name. Furthermore, since the script loops through all worksheets, you must somehow prevent it from executing when it encounters these parameters worksheets. To do that, I have built in an if statement. See the fully edited version of the script below:





myinc=1;
doc -e W
{
%A=%H; // store active window name
if(%[%A,11]!="Parameters")
{
%B=nlsf.func$;
nlsf.init(); // initialize the fitter
nlsf.begin(); // complement to end()
nlsf.func$=MyLine; // initialize function to be used
nlsf.p1=0.1; // initialize the parameter values
nlsf.p2=0.1;
nlsf.fitData$=%(%A,4); // initialize the dependent dataset
layer -a; // rescale the graph when it comes up
nlsf.wType=2; // statistical weighting
nlsf.fit(100); // 100 iterations
nlsf.xmode=0; // use same X as fit data
run.section(fit.ogs,ParaConf,Parameters$(myinc));
myinc++;
nlsf.end(); // forces After Fit to run
}
};




I hope that all this makes sense. And BTW, I'm a big fan of Japanese food.

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