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
 Labtalk Nonlinear curve fitter
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

simarwood

UK
Posts

Posted - 11/08/2004 :  09:28:12 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
I use Origin 6.0 and am completely new to Labtalk.

I want to fit my own defined function {y = k + (1-exp(-x/tor))} to data in an iterative manner (with time, per second) and churn out the chi-squared and parameter data at each time point.

Can anybody help me on where to get started / learn more?

I assume I need to run a loop to keep fitting the response whilst incrementing the last data point to fit by one each time.

easwar

USA
1965 Posts

Posted - 11/08/2004 :  12:15:11 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

I presume you want to fit to a different section of the data each time. You can do this by programming the LabTalk nlsf object. You can then use the mks1 and mks2 system variables to set data markers to select various subsets of our data and fit each subset using a loop.

A crude example is pasted below. You could look in LabTalk help files for details and then refine the example as needed.

Before you run code (such as this), I suggest you first define/create a new fitting function and then save that function (in the example below, I call it MyFunc). You can then load your special function from the code such as below and then fit with it.

To try this code, first create your function, then graph your data, then copy and paste all lines of the code to the Script window, select/highlight all the lines, and press Enter key to execute.

Easwar
OriginLab


// Get length of active dataset
limit %c;
// Number of groups =length / 10
numgroup = (limit.size) / 10;
// Initialize NLSf object
nlsf.init();
// Assign function
nlsf.func$="myfunc";
// Point to active dataset
nlsf.fitdata$=%c;
// Loop over each group of points in active dataset
for(i = 1; i <= numgroup; i++)
{
// Use mks1, mks2 to set data markers
mks1 = 1 + (i - 1) * 10;
mks2 = i * 10;
// Give some initial value to parameters
// Can be replaced with more elaborate initialization code
nlsf.p1=1;
nlsf.p2=0.1;
// Iterate
nlsf.iterate(100);
// Report to script window
type Data Fitted from $(mks1) to $(mks2);
type Param1: $(nlsf.p1) +/- $(nlsf.e1);
type Param2: $(nlsf.p2) +/- $(nlsf.e2);
type Reduced ChiSqr: $(nlsf.chisqr);
type "";
}


Go to Top of Page

simarwood

UK
Posts

Posted - 11/09/2004 :  05:18:15 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Many thanks for the script example. It didn't work, but it has given me some idea of the way in which the code is written.

I wish it was Excel Basic, this labtalk stuff is difficult!

Go to Top of Page

simarwood

UK
Posts

Posted - 11/09/2004 :  05:25:31 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I have realised I threw you a bit of a dummy, the curve should be:

y=k+(p1*(1-exp(-(x-21)/p2)))

But if I define this function properly then I suppose it shouldnt affect the code you sent
Go to Top of Page

easwar

USA
1965 Posts

Posted - 11/09/2004 :  09:20:07 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

As long as you create the FDF with the function you want to fit with, the code segment posted here can work with the FDF, but you will need to change the parameter initialization code accordingly. Note that I just used some hard coded values such as p1=1. You may want to replace that with your own code, or you may want to enter the para init code in the FDF itself and then call the appropriate nlsf method to run the para init code.


Easwar
OriginLab

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