05-08-2017 08:53 PM - edited 05-08-2017 08:53 PM
I am trying to fit to a nonlinear equation in the form y = (a*b*x)/(b+x) to solve for a and b. Up till now I have been solving for a and b by using the Solver add in in Excel, but would like to do this in LabVIEW to speed up the post processing time. In the attached VI is a constant that is like the data I will be getting from my full program. I have already done my normal post processing to see what a and b should be for this data set. They are listed in the VI as well. Any suggestions would be appreciated.
I would like to do it without using Express VI’s if possible.
Thanks!!!
Solved! Go to Solution.
05-08-2017 10:53 PM - edited 05-08-2017 10:58 PM
As a quick first comment, your X and Y inputs are backwards, I think!
However, swapping them and solving gives
a: 0.00377929
b: 9715.5
which isn't exactly what you wanted!
However, the mean of the y-y_predicted is 0.
Is it a possible second solution?
Edit: I checked the mean fractional error avg((y_predicted - y)/y * 100) and the result is 34%. That doesn't sound great to me, but I don't know...
05-08-2017 11:24 PM
I agree with cbutcher (about X and Y being backwards, and about the "wrong answer" being returned). Curiously, the answer doesn't change if I move the Starting Point, nor if I remove the (0, 0) data entries, suggesting that the algorithm isn't (by default) converging well. I'm currently a little sleep-deprived, so can't do much more tonight ...
Bob Schor
05-09-2017 09:44 AM
Haha. Yes I did have them backwards. However this is still not giving me the correct solution. Would using an optimization function be a better solution?
05-09-2017 11:47 AM
If I was confronted with that type of problem,
I would try to use this: http://zone.ni.com/reference/en-XX/help/371361M-01/gmath/con_nonlin_curve_fit/
instead of : http://zone.ni.com/reference/en-XX/help/371361H-01/gmath/nonlinear_curve_fit/
Moreover, there's this nicely written guide from altenbach about non-linear curve fitting:
http://forums.ni.com/t5/Nonlinear-Fitting/Practical-Nonlinear-Fitting/gpm-p/3511655
05-09-2017 02:16 PM
The results returned from LabVIEW have a lower error than the results returned from Excel. Using the "Goodness of Fit.vi" the SSE from the Excel results is 0.2358401. This agrees with the 'Error' value in the spreadsheet. The SSE from the LabVIEW results is 0.2331595.
05-11-2017 08:48 AM
@DSPGuy wrote:
The results returned from LabVIEW have a lower error than the results returned from Excel. Using the "Goodness of Fit.vi" the SSE from the Excel results is 0.2358401. This agrees with the 'Error' value in the spreadsheet. The SSE from the LabVIEW results is 0.2331595.
Moreover, EXCEL has a rounding issue occurring at about 1E-9, which doesn't affect you, if you stay in the EXCEL world e.g.
copy coefficients from EXCEL 2003 to EXCEL 2016.
But it will heavily affect you e.g. if you calculate regression coefficients in EXCEL and than want to use those in LabView
Also, if you use EXCEL to calculate regression tasks, EXCEL 2003,2007 results may differ from EXCEL 2013, 2016
05-11-2017 08:43 PM
I used the last link that alexderjuengere suggested to get me to a point that I am happy with. Using the "Goodness Fit.VI" I feel pretty confident in my answer. Thanks for all the suggestions and help!