05-15-2013 09:13 PM - edited 05-15-2013 09:29 PM
Hi all,
I met some problems about using constrained nonlinear curve fitting vi. It seems to me that this vi can't properly deal with the function like ln(1+b(x-xc)/a), a,b, and xc are the parameters, and b is in the range of 0 and -1. The reason I said that is as I used the other nonlinear fitting function in the other software, like Originlab, the fitting function can work properly.
The error message from LV occurs as 1+b(x-xc)/a is less than zero.
However, due to a,b are both adjustable parameters, how could this situation happen ?
Now I attach the vi files. The attachment includes main vi, mathmatical formula, and an input XY txt file.
I appreciate any help or suggestion from you!!
Here is the error message
Joy
Solved! Go to Solution.
05-16-2013 03:31 AM
I'm not really familiar with the math involved, but just by stepping through your code, I see that your coefficients turn to NaN already after the first while loop iteration in NLCF LM bound.vi which causes the Matrix Left DivisionMV.vi in LM get new coefficients.vi to fail. Maybe step through the code yourself, which will give you a better idea.
How did you validate your LN-fittingmodel.vi? Did you consider implementing it using a Mathscript node? Personally I find (graphical) LV implementations of formulae somewhat unintuitive to read and therefore hard to maintain and debug.
Best regards
05-16-2013 04:45 AM
Thanks for reply. whitenoiz
Actually I have more than 100 XY data set to test my vi. Some of the data set can be fit flawlessly. And the best fit parameters obtained from my vi are exactly the same as those from other analytical software, like OriginLab. In this case, I know my vi is valid. And in this scenario, I also found 1+b(x-xc)/a is always larger than zero with the best fit parameters (a and b). However, for certain XY data set, the error message will pop up if I use LV built-in vi, but I still can obtain the best fit parameters with OriginLab. And then I realized that error message always pops up as 1+b(x-xc)/a is less than zero, which it means to me that as LV built-in vi handles this type mathematical function, this built-in vi will encounter some difficulties.
I will step through my code, and also focus on the Matrix Left DivisionMV.vi, try yo find where the problem is.
Best regards,
Joy
05-16-2013 05:49 AM
I took a quick look at OriginLab and found that it features LabVIEW connectivity. Maybe that could allow you to do your NL fitting in OL and plug that back into another VI!?
http://www.originlab.com/index.aspx?go=Products/Origin/CollaborationAndConnectivity/LabView
05-16-2013 09:20 AM
Try using the "In Range and Coerce" primitive just before the Ln primitive to coerce the values to something greater than zero. I used upper limit = Inf, and lower limit = machine epsilon, and the error disappeared.
-Jim
05-16-2013 09:51 AM
Great thanks, Jim.
Your suggestion truely solves my problem!!!
Joy
05-16-2013 12:02 PM
Then mark Jim's post as the solution to your problem rather than your own thank you message.