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
 User defined fitting functions-Parameters
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

kemeyer

39 Posts

Posted - 07/26/2010 :  10:41:06 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 8.0 SR6
Operating System: Vista

I had a question about setting up a fitting function. What I am trying to do it this:

First, I fit equation 1:

y=sqrt( A + B*Lambda^2/(Lambda^2-C) + D*Lambda^2/(Lambda^2-E) )

Where the independent variable is Lambda, the dependent variable is y, and the parameters are A, B, C, D, and E. I use the code:
A=2.0;
B=1.5;
C=0.05;
D=1.7;
E=160.0;
To initilize the parameters.

After I get values for these parameters, I use them in to equation 2, which is a Temp. Dependent version of the first:

y=sqrt( A + B*Lambda^2/((Lambda^2-C)(1 + alpha(T-23))) + D*Lambda^2/((Lambda^2-E)(1 + alpha(T-23))) )

Where the independent variable is T, the dependent variable is y, and the parameters are Lambda, alpha,A, B, C, D, and E. The Parameters Lambda, A, B, C, D, and E will be fixed.

My problem is: I don't know how to get the final fit values of A, B, C, D, and E from equation 1 and assign them to the parameters in equation 2.

I've tried type into the script after fitting some code to set a LabTalk variable equal to the Origin C variables, such as:
LT_set_var("A", A);
But this did not work.

In what ways can I access the ending values of the parameters and how can I set the parameters of the second equation to those values?

Thanks,
Katie

larry_lan

China
Posts

Posted - 07/27/2010 :  09:42:04 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I guess the initial value for the second fit comes from the result of the first fit, right? If so, I think you may need two individual fits. Then, you can copy the result from first fit and paste to the Value column of second fit.

However, if you don't want to do that manually, I am afraid maybe you need to do the fits by Scripts. Here are some starting example to perform fitting by LabTalk Script. And again, you also need two individual fits, and you can use some variables to hold the result from the first fit, and assign these variables as initial values for the second fit.


Thanks
Larry
Go to Top of Page

kemeyer

39 Posts

Posted - 07/27/2010 :  10:05:49 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Yes, the initial value for A, B, C, D, and E for the second fit come from the first fit.

I've done some labtalk programming of fits already so I am somewhat familiar with how to retrieve the information from the results tree. However, can the assignment of the final value for first fit of A, B, C, D, and E be done within the user defined function? I saw there was a section when defining a function of code to execute afterward, but when I added the LT_set_var("A", A); (Origin C) it said it did not recognize it or something of that nature.

If this doesn't work, I can simply get the values from the tree and assign them to variables, but I was wondering if I could take care of it when defining the function.

Thanks,
Katie
Go to Top of Page

easwar

USA
1964 Posts

Posted - 07/27/2010 :  10:53:54 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Katie,

The cleaner way is what Larry suggested - write script to fit the data, and at the end of the first fit get the tree with values and use those values to set the initial values of parameters in the tree for the 2nd fit.

If you instead want to do this in the GUI, then you need to save the parameter values some place (such as global LabTalk variable, or a file on disk) by writing some script in the "After Fit" script box of the first function. You will need to get the tree to get the values. And then for the 2nd function you will need to write some code in the "Parameter Initialization" block to go get the values saved (from variables or file) by the first function.

Easwar
OriginLab
Go to Top of Page

kemeyer

39 Posts

Posted - 07/27/2010 :  1:32:14 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Alright, that sounds good. My aim was to automate the fitting as much as possible so I will be doing the fitting via code instead of the GUI in any case. Thank you for all the help!

Katie
Go to Top of Page

larry_lan

China
Posts

Posted - 07/27/2010 :  11:07:41 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Katie:

This is a simple script example for your case. Please modify it as you need. There are two functions in this example, where

myfunc1 = a + b*x;
myfunc2 = a - b*x;

Then, you can run some script like:

// Fit from worksheet in this example
// The first fit
nlbegin iy:=2 func:=myfunc1 nltree:=tr1;
// Assign initial values for myfunc1
tr1.a = 1;
tr1.b = 1;
nlfit;
nlend;

type Now, the parameter values for myfunc1 are saved in tr1;
type tr1.a is $(tr1.a);
type tr1.b is $(tr1.b);

// The second fit
nlbegin iy:=2 func:=myfunc2 nltree:=tr2;
// Set initial values for myfunc2
tr2.a = tr1.a;
tr2.b = tr1.b;
nlfit;
nlend 1; // Output report worksheet

type Then, new parameter values for myfunc2 are saved in tr2;
type tr2.a is $(tr2.a);
type tr2.b is $(tr2.b);


Hope this helps.

Thanks
Larry

Edited by - larry_lan on 07/27/2010 11:40:25 PM
Go to Top of Page

larry_lan

China
Posts

Posted - 07/27/2010 :  11:39:02 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Another way is do that in GUI. Then, you should modify the definition of the second function.

Take the above two functions as example. Before defining MyFunc2, you can write some script like:

// Script name is "RunMyFunc1.ogs"
nlbegin iy:=%C func:=myfunc1 nltree:=tr1;
// Assign initial values for myfunc1
tr1.a = 1;
tr1.b = 1;
nlfit;
nlend;


This script is used to run MyFunc1 and get the results.

Then, in the initialization code of MyFunc2, write something like:

LT_execute("run.section(RunMyFunc1.ogs)");
// Get the tree results to parameter a & b
LT_get_var("tr1.a", &a);
LT_get_var("tr1.b", &b);


Save MyFunc2, then you can fit the curve from graph window, and the parameter initial values will be set properly.

Hope this helps. And please change the function as you need.

Thanks
Larry
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