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
 Curve fitting - fastest approach
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

peter.cook

UK
356 Posts

Posted - 12/12/2003 :  09:02:32 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi,

Can you please confirm the fastest method to fit to user defined functions?
I would still want to define initial parameters and the consttraints required for each fit.

I assume this would be using a user defined dll (not all would have access to create these..).

Currently use LabTalk - will Origin C actually help here?

Cheers,

pete



easwar

USA
1965 Posts

Posted - 12/17/2003 :  3:22:31 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Pete,

External DLL would be the fastest option, but as you point out, not the easiest - will need tools like Visual C to create DLL etc.

I would recommend that you first switch to Origin C from LabTalk. For complex, multi-line functions Origin C will be faster than LabTalk. Plus with Origin C you can utilize some of the functions in internal.c such as xatymax(), xaty50() etc. in writing custom parameter initialization code for your custom functions. We use these functions in the parameter initialization code for our built-in functions. Also it is much easier to debug your fitting function when using Origin C as opposed to external DLL.

Easwar
OriginLab.


Go to Top of Page

peter.cook

UK
356 Posts

Posted - 12/18/2003 :  07:19:52 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi easwar,

Thanks for reply. I do have Visual C and have set up some simple dlls. I guess my question is is there an optimum way to include these in code for customised apps eg currently I just use LabTalk and only reference to dll is in .fdf file.

Also, could you actually incoporate some initial parameterisation into the curve fitting dlls rather than separate routine outside dll?

Cheers,

Pete

Go to Top of Page

Laurie

USA
404 Posts

Posted - 02/12/2004 :  2:17:31 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Peter,
You would have to initialize the parameter values outside of the DLL. The function defined within the DLL gets called during each iteration. The fitter is designed such that the parameter init is separate from the equation. You can use Origin C to write parameter init code, on the Scripts:Parameter Initialization page.

Can you explain more what you need when you ask the following:
"I guess my question is is there an optimum way to include these in code for customised apps eg currently I just use LabTalk and only reference to dll is in .fdf file. "

Thank you,
Laurie




OriginLab Technical Support
Go to Top of Page

peter.cook

UK
356 Posts

Posted - 02/13/2004 :  03:58:28 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Laurie,

Thanks for reply.

OK, so I have to provide intial estimates outside dll and these are used by fitter.
Best way might be to use Origin C then depending on nature of algorithm we use and possibly using some of internal functions as Easwar suggested.

My other question was along the lines of :

Currently I use LabTalk for all fitting proceedures eg

- roughly -


nlsf.begin();
nlsf.category(PetesFunctions);
nlsf.fitdata$="Pete_Data";
nlsf.func$="PetesEquation"; // excuse the egomania..

PetesInitialParametersMacro; // using LabTalk, dose range, mean of replicates..

nlsf.p1=1;
nlsf.p2=2;
nlsf.p3=3;

nlsf.iterate();

KeepParameter1=nlsf.p1;
KeepParameter2=nlsf.p2;
KeepParameter3=nlsf.p3;
KeepChisqr=nlsf.chisqr;

..etc

(I do like the new feature of not creating graphs as build 816)

Is there an optimal way to do the above via Origin C or do we still call nlsf fitter via LabTalk and retrieve parameters....?

Cheers,

Pete

Go to Top of Page

easwar

USA
1965 Posts

Posted - 02/13/2004 :  9:01:37 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Pete,

You can access the nlsf object from OriginC with code such as:

void myfunc()
{
//
using nlsf = LabTalk.nlsf;
nlsf.begin();
nlsf.category("PetesFunctions");
nlsf.fitdata$="Pete_Data";
nlsf.func$="PetesEquation";
//..
// use special functions to initialize params
Dataset dsData("Pete_data");
nlsf.p1=max(dsData);
nlsf.p1=2;
//etc
nlsf.iterateex();
// etc
}

Easwar
OriginLab.


Edited by - easwar on 02/13/2004 9:04:34 PM
Go to Top of Page

peter.cook

UK
356 Posts

Posted - 02/16/2004 :  05:50:35 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Easwar,

Thanks for this.

So, I'll have a curve fitting function dll when available and call fitting via Origin C using Origin C to generate initial parameters.

I like it.

One question, do I need to call nlsf.begin() or nlsf.category() or other properties/methods within the Origin C function. I assume that you are just calling/referring to existing properties IF they are already set?

Cheers,

Pete



Edited by - peter.cook on 02/16/2004 05:51:02 AM
Go to Top of Page

Laurie

USA
404 Posts

Posted - 03/17/2004 :  8:32:43 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Peter,

Inside the fitter, when you select Function:New to define a new function, it can be of Type:User-Defined or External DLL.

When you create a new, user-defined function, the NLSF default setting is to use Origin C. This option offers the most speed and flexibility for defining your function. If you uncheck the Use Origin C check box, the Form drop-down list is available: Expression, Y-Script, or Equation

When performing a fit from script, you use the NLSF object. If you were to use Origin C instead of LabTalk, there is no NLSF object in Origin C, but like Easwar mentioned, you can access the NLSF object from Origin C using the following: using nlsf = LabTalk.nlsf;

There is no advantage of doing this unless the C function contains other code. In the example that Easwar gave, there is code to initialize the parameter values.

The other option is to write a parameter init routine on the Scripts:Parameter Initialization Page. This can be written in Origin C (Use Origin C checkbox checked) and will then get saved with the FDF file. Then there is no need to use nlsf.p1= in your fitting script. You would need to use the following:

nlsf.execute(parainit);


Does this help?

OriginLab Technical Support
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