07-06-2009 07:27 AM
I am working with an experiment that gives me X- and Y- data that I need to fit to a theoretical model (somewhat involved). I use to do this in matlab using the "lsqcurvefit", which works fine, but for varous reasons I need to do this in LabView instead.
So, first thing I did was to make a vi which is my theoretical model. I throw in my X-data and get the Y data out of it.
This vi works fine of it's own, but now I want to do my fitting by calling the model-vi from the Nonlinear curve fit.vi. I enter the same initial parameters, termination conditions, upper- and lower boundaries as in the matlab code, but no matter what, after some 100 function calls, the curve fit interrupts and tells me:
"Error -20041 occurred at NI_Gmath.lvlib:Nonlinear Curve Fit LM.vi
Possible reason(s):
Analysis: The system of equations cannot be solved because the input matrix is singular."
I have tried to locate the problem at varoious levels but I get confused when I start to look into the nonlinear curve fit vi, I just lose myself in tons of block-diagrams.. Can anyone see what my problem is? I'd sure appreciate it! I added the necessary files. Main vi: langevin fit. vi, then open the data.txt.
Thanks
07-06-2009 07:53 AM
Hi there
At the first level of debugging always assume the NI-VIs do what tey're told. In almost all cases it dosn't make sense to look inside the NI VIs.
In your case: Check the inputs of the NumericalOptimization\Nonlinear Curve Fit LM.vi.
Place a 2D double indicator to the "Read From Spreadsheet File (DBL).vi" and you'll see that you get an y-array containing just 0's. Check this first.
07-06-2009 08:08 AM
Hi Chris.
I see what you mean, but can this row of zeroes really affect the curve fit vi? I do not pass it on to the NI curve fit- vi; the y-data going into my curve fit-vi is OK as far as I can see...
Regards,
/Fredrik
07-06-2009 08:15 AM
07-06-2009 08:24 AM
Hi again Chris
There must be something we're not doing the same way. The data.txt provides me with a good set of x-and y-data which I can see in the graph on my front panel (wired to the inputs of the curve fit vi) as well as in probes that I placed right on the inputs of my curve fit-vi.
Thanks
/Fredrik
07-06-2009 08:28 AM
I just realized, could it be that we have different settings of the decimal symbol? I use the period ".", but I know many people use the default comma sign ",".
Regards,
/Fredrik
07-06-2009 09:02 AM
OK, shame on me, you're right.
Well, then test if the "Particlesystem magnetization function.vi" actually does what it is expected to.
07-06-2009 10:55 AM - edited 07-06-2009 10:59 AM
Your model function does not produce anything resembling your data. As a first step, graph the data using your initial guesses, here's how it would look.
Here' the data and your initial guess on the same graph. You need to find initial guesses so the output resembles your data.
My best guess is that your model is faulty. It is very hard to debug, because it is a mess: deeply stacked sequence structures and unneeded local variables. Also the model parameter constants should be provided via the "data variant" input instead of a global variable. You have a weird mix of datatypes. Why is half of the stuff EXT instead of DBL for no reason?
I would also highly advise NOT to color your own VIs light yellow. Don't make them look like system tools! 😉
I am busy today, but maybe I can have a stab at it tonight. Good luck!
07-07-2009 12:26 AM
Hi fahrentorp,
I think you give wrong Initial Guess. In your model, you only have 3 parameters. But you have an unnecessary "0" in your Input guess array.
If you remove the 4th element, 0, in the input array a, you can get the reasonable result from nonlinear fit VI.
Regards,
Michael
07-07-2009 04:03 AM
Hi altenbach
Thanks for taking time to look at the problem even though you are busy.
First of all, the curve fit now finishes without errors thanks to the solution suggested by Michael below. The fit parameters are not the same as matlab yet though.
I don't really get the same discrepancy between data and guess as you show in the graph. I do agree that the initial guess could be better, but the shape the curves are the same. The guess could be improved considerably by increasing the last parameter from 1 to 8, but the end result still not good enough.
The reason for the messy model is partly because I went "trial&error" when I ran out of ideas to get things working. For a while I thought that some numbers were too small for the DBL datatype, but that was just a wild guess. As for the structure..well, I guess it could be improved, I simply adopted
my matlab structure (which needs one for-loop inside the other). I use sequences to save screen space, but I am sure it's possible to simplify things.
Regarding the use of the global variable, it was my last resort solution, I kept looking for documentation as to how to pass parameter constants to my model, but there really wasn't a lot written about the data input format in the labview help file.
Of course you are right about the sub-vi color, I will change that.
Anyhow, thanks for your help.
Cheers
/Fredrik