Author |
Topic  |
|
rwusf
USA
Posts |
Posted - 09/07/2006 : 12:13:28 PM
|
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
|
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 |
 |
|
rwusf
USA
Posts |
Posted - 09/08/2006 : 10:03:09 AM
|
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.
|
 |
|
rwusf
USA
Posts |
Posted - 09/08/2006 : 11:34:27 AM
|
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
|
 |
|
zachary_origin
China
Posts |
Posted - 09/08/2006 : 1:35:41 PM
|
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 |
 |
|
rwusf
USA
Posts |
Posted - 09/08/2006 : 3:41:57 PM
|
Hi Zachary,
I got what you meant now. And things are totally fixed! Thanks a million...
Best Wishes, Rick
|
 |
|
|
Topic  |
|
|
|