LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

constrained nonlinear curve fit can properly handle the function like ln(1+b(x-xc)/a) ?

Solved!
Go to solution

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

 

Picture1.png

 

 

Joy

Download All
0 Kudos
Message 1 of 7
(4,709 Views)

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

0 Kudos
Message 2 of 7
(4,675 Views)

Thanks for reply. whitenoiz Smiley Happy

 

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

 

0 Kudos
Message 3 of 7
(4,671 Views)

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

 

 

0 Kudos
Message 4 of 7
(4,666 Views)
Solution
Accepted by topic author JoyChung

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

Message 5 of 7
(4,658 Views)

Great thanks, Jim.

Your suggestion truely solves my problem!!!Smiley Very Happy

 

Joy

0 Kudos
Message 6 of 7
(4,649 Views)

Then mark Jim's post as the solution to your problem rather than your own thank you message.

0 Kudos
Message 7 of 7
(4,634 Views)