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
 Help on defining a new function for NLSF!!
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

rwusf

USA
Posts

Posted - 09/07/2006 :  12:13:28 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi all,

I was trying to define a new function, y=a+b*(c-x)^n (x is the independent variable, y is the dependent variable, a, b, c and n are parameters), to perform nonlinear fitting for my experimental data. Unfortunately, since I am not familar with Origin C or other languages at all, I was having a hard time figuring out how to initialize the parameters during the process of definging the equation. So I was wondering if anyone would knidly help me on this. Thank you very much in advance for your time and kindness!

By the way, the closest built-in equation within Origin I found is y=y0+A*|x-xc|^p with the following parameters initialization:

[Parameters Initialization]
sort( x_y_curve );
smooth( x_y_curve );
y0=min(x_y_curve);
xc=xatymin(x_y_curve);
x_y_curve = ln(x_y_curve-y0);
Dataset dx;
x_y_curve.AttachX(dx);
dx = ln(dx-xc);
double coeff[2];
fitpoly(x_y_curve,1,coeff);
A=exp(coeff[0]);
P=coeff[1];

zachary_origin

China
Posts

Posted - 09/07/2006 :  10:57:44 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,
Try this:

sort( x_y_curve );
smooth( x_y_curve );
double coeff[2];
fitpoly(x_y_curve,1,coeff);
double k = coeff[1];
if(k > 0)
{
a = max(x_y_curve);
c = xatymax(x_y_curve);
}
else
{
a = min(x_y_curve);
c=xatymin(x_y_curve);
}
x_y_curve = ln(fabs(x_y_curve-a));
Dataset dx;
x_y_curve.AttachX(dx);
dx = ln(fabs(c-dx));

fitpoly(x_y_curve,1,coeff);
if( k > 0 )
b=-exp(coeff[0]);
else
b = exp(coeff[0]);
n=coeff[1];



BTW, if you know the approximate scope of the parameters, you can directly set the value of the parameters.

Hope it helps.



Zachary
OriginLab GZ Office
Go to Top of Page

rwusf

USA
Posts

Posted - 09/08/2006 :  10:03:09 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
It works great!!!!! Thank you so much, Zachary! I really appreciate your kindly help and quick response.

Sincerely,

Rick
FL, USA


PS: I knew I could manually set the initial parameters, but in this case, it is hard to guess the scopes and in other cases when I did try, they hardly worked.

Go to Top of Page

rwusf

USA
Posts

Posted - 09/08/2006 :  11:34:27 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Zachary,

Something pretty weird happened though. I used the parameters initilization you provided for me to fit the data and it worked perfectly for the very first trial. However, if i repeated the nonlinear fitting for the same data set or tried for a different one under the same conditions, the automatic parameters initialization didn't seem to be working although I did check "Enable Automatic Parameter Initialization " at the time when I edited the equation. Of course it is not a big problem now since I've had some ideas about the range of the parameters from the first trial. I am just curious about what causes this and I would love if I don't have to manually set the values every time since I am working with a large number of data sets. But don't worry about it if this is beyond your time or effort.

Thanks again,
Rick

Go to Top of Page

zachary_origin

China
Posts

Posted - 09/08/2006 :  1:35:41 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Rick,

I never meet the problem you mentioned above.
I am not sure if you mistook the NonLinear Curve Fitting: Parameter Initializations dialog(select Scripts:Parameter Initialization in the menu) with the NonLinear Curve Fitting: Fitting Session dialog(select Action:Fit in the menu). Can you see the initialized value in the Fitting Session dialog? If it works there, you do not need to set the values in Parameters Initialization dialog. Just my imagination, not sure.



Zachary
OriginLab GZ Office

Edited by - zachary_origin on 09/08/2006 1:39:39 PM
Go to Top of Page

rwusf

USA
Posts

Posted - 09/08/2006 :  3:41:57 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Zachary,

I got what you meant now. And things are totally fixed! Thanks a million...

Best Wishes,
Rick

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