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 two dependent one independent not working
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

smtanner

USA
Posts

Posted - 07/26/2006 :  4:20:11 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): 7.5
Operating System:windows

I am having a problem fitting two dependant variables to one independant variable in labtalk. I have a function defined in the advanced curve fitter which works fine and looks similar to this:

independant: x
dependent: y1,y2
parameters:a,b,c

y1=ax+bx^2
y2=ax+cx^2

As you can see the equations share one parameter. The problem I have is if I run the advanced curve fitter if will fit both equations just fine but if I try to use labtalk, it will fit y1 fine but the fit to y2 is off a little. My labtalk code is:

nlsf.cleanupfitdata();
nlsf.func$="resonancefirst";
nlsf.y1$=a$(i)fit_real;
nlsf.y2$=a$(i)fit_imag;
nlsf.x$=a$(i)fit_frequency;

*\initialize the parameters\*
sum(a$(i)fit_frequency);
resfreq=sum.mean;
resmin=sum.min;
resmax=sum.max;
xoff=0;
yoff=0;
amp=.05;
gamma=30000;
xslp=0;
yslp=0;
theta=0;

nlsf.derivStep = 0.0001;
nlsf.chiSqrErr=1;
nlsf.wType=3;
nlsf.w1$=a$(i)fit_error;
nlsf.w2$=a$(i)fit_error;
nlsf.tolerance=1E-13;
nlsf.v5=0;
nlsf.v6=0;
nlsf.v3=0;
nlsf.v4=0;
nlsf.v1=1;
nlsf.v2=1;
nlsf.v7=1;
nlsf.v8=1;
nlsf.iterate(10);




nlsf.v5=1;
nlsf.v6=0;
nlsf.v3=1;
nlsf.v4=1;
nlsf.v1=1;
nlsf.v2=1;
nlsf.v7=1;
nlsf.v8=1;
nlsf.iterate(20);



nlsf.v5=1;
nlsf.v6=1;
nlsf.v3=1;
nlsf.v4=1;
nlsf.v1=1;
nlsf.v2=1;
nlsf.v7=1;
nlsf.v8=1;
nlsf.constraints=1;
nlsf.constr$="gamma>10000;resfreq>resmin;resfreq<resmax";
nlsf.fit(200);


Is there something wrong with this code?

Edited by - smtanner on 07/26/2006 5:22:09 PM

smtanner

USA
Posts

Posted - 07/26/2006 :  6:03:30 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
After looking at it closer, it looks like the labtalk code is optimizing the shared variable using y1 only. This provides an ok fit to y2 but it should be optimized for y1 and y2 both.

The advanced curve fitter is fitting much better than the labtalk code but I have way to many datasets to do this by hand.

thanks
shawn
Go to Top of Page

Deanna

China
Posts

Posted - 07/26/2006 :  11:26:36 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I wonder if the problem is related to not setting the first parameter as shared.

Would you please send us your data via tech@originlab.com? It might help us in finding a solution.

Deanna
OriginLab GZ Office
Go to Top of Page

smtanner

USA
Posts

Posted - 07/27/2006 :  10:56:41 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Ok, this seems to be a problem with the way I am defining the weighting method. I am using a data column as an arbritrary dataset weighting for each dependent variable. The three lines in my code:

nlsf.wType=3;
nlsf.w1$=a$(i)fit_error;
nlsf.w2$=a$(i)fit_error;

are for this purpose. If I remove these lines, the fitting works as it should. Is this the correct syntax for this. If not, what is the correct syntax, or what command does the advanced curve fitter use for this?

thanks
shawn

Edited by - smtanner on 07/27/2006 11:23:10 AM

Edited by - smtanner on 07/27/2006 1:03:10 PM
Go to Top of Page

fzimnoch

USA
28 Posts

Posted - 07/27/2006 :  1:24:19 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello Shawn:
quote:


If not, ....... what command does the advanced curve fitter use for this? thanks shawn




If you set up the Advanced Curve Fitter with two dependent variables that each have an associated set of errors then when you go to the Advanced Curve Fitter complete the information in Action>Datasets then Options>Control will have show the two dependent datasets in the Dependent Variable window. Click on them individually to choose the appropriate weighting method.

To do this from the GUI its best to have Y errors immediatley to the right of the Y values.

FRED
Go to Top of Page

smtanner

USA
Posts

Posted - 07/27/2006 :  1:52:04 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
This doesn't help with automating in labtalk though. It already works correctly in the advanced curve fitter. What I need to know is how to assign weighting columns in labtalk.


thanks
shawn
Go to Top of Page

smtanner

USA
Posts

Posted - 07/27/2006 :  4:35:49 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Ok, after some thought, I understand what is happening (I think). The code I am executing for the weighting:

nlsf.wType=3;
nlsf.w1$=a$(i)fit_error;
nlsf.w2$=a$(i)fit_error;

is not setting the weight for the second dependent variable y2. Instead it is weighting y1 only and that is why y1 is being preferentialy fit and why if I take out the weighting, I get the correct fit (since right now I am just just using a constant value for the weight). In fact if I go into the advanced curve fitter and apply the weight to y1 only, it produces the same poor fit of y2 as seen using the labtalk script.

So the question is what is wrong with the three lines of code above?
Go to Top of Page

zachary_origin

China
Posts

Posted - 07/28/2006 :  02:27:03 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Shawn,

If it is really the matter as you mentioned, you can change the lines to :

nlsf.wType1=3;
nlsf.wType2=3;
nlsf.w1$=a$(i)fit_error;
nlsf.w2$=a$(i)fit_error;

Zachary
OriginLab GZ Office
Go to Top of Page

smtanner

USA
Posts

Posted - 07/28/2006 :  10:42:17 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Great, that fixed it.

thanks
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