LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Non-linear curve fiutting help needed

Solved!
Go to solution

So I have to develop a non linear fitting program to fit our experimental data. At frist I wasn't sure which of the instances I should use: either the vi or the string one. I decided on the vi version after looking through the previous posts made on this forum. Given that I was unsure how to select the parameters, I had a look at the vi that has been discussed in this thread and used that as template of what I might need to do.

 

However I have run into a problem. I get the following error:

Error -20041 occurred at NI_Gmath.lvlib:Nonlinear Curve Fit LM.vi:5

Possible reason(s):

Analysis: The system of equations cannot be solved because the input matrix is singular.

 

I can't work out why I am getting this error in the curve fit vi. Also if I then continue with running the vi, the values in the best fit parameters now just match those in the initial fitting parameters. The parameters I have used are fairly close to the known numbers (ie the ones I used to calculate my 'data'), and they have been selected as the default values.

 

Any help on this would appreciated. I have attached 3 vi's. One is the fitting vi, another the fitting function and the third being a vi for the weight. The function I am trying to fit is given in the fitting function vi. The equation to calculate the weight is given in the weight vi. I should also note that the data I have attached is not from my actual experiment (hence my calling it fake data), but it is typical of the sort of data I will be getting. I have included header info in this data file as this is the style the data will come in, so to is location of the data columns (have only filled the relevant columns with data for the purposes of developing the fitting program).

 

I am using Labview 8.6.

0 Kudos
Message 1 of 17
(7,755 Views)

hi

can you check that the determinant of the matrix is not  zero ? maybe you have a typo in the data

N

0 Kudos
Message 2 of 17
(7,744 Views)
Your weights are all zero! I suspect that your energies are not really in units of kT.
Message Edited by altenbach on 05-25-2009 12:54 PM
0 Kudos
Message 3 of 17
(7,739 Views)
Solution
Accepted by topic author scottum

I think your units are all messed up! 😮

 

You would get a great fit if you do the following two changes:

 

  • don't wire the weights! (you first need to sort out the units!)
  • Modify the model function to divide the current result by ~4E-21 (see image) There is probably an exact factor that can be determined from first principles. I did not bother, because I don't know what the model is all about. ;).

 

 

 

Here's an example fit with slightly off starting values (data -Fit is much less than one percent):

 

Message Edited by altenbach on 05-25-2009 02:40 PM
Download All
0 Kudos
Message 4 of 17
(7,728 Views)
Thanks for the quick response.  I haven't had a chance to make the alterations you suggested altenbach (a combination of working on another vi and also some stuff in the lab), but what you have done indicates I need to rework my code abit and also to look at the weighting factor as well.  Thanks again for your help.
0 Kudos
Message 5 of 17
(7,686 Views)

So I was trying to work out where I was missing that 4E-21 factor from.  It works out that I don't need to work the value out from first principles, but rather I need to divide the result by kT (since the potential energy is in terms of kT).  So, altenbach, your figure of 4E-21 was indeed pretty close to the mark! :)n  Looking back it was so simple, but just didn't pick it u.

 

I still need to work on the weighting issue.  Thanks for your help on this, it is much appreciated! 🙂

Message 6 of 17
(7,649 Views)

I do have another question though.  Becuase I have to divide by kT now, i need to have a temperature value here.  I would prefer to be able to input the temperature as needed (even though it is unlikely to change that much).  Thus I want it to be an indicator.  Since I am using this sub-vi (this is the fit function vi) in my fitting vi as a strictly typed vi and and am it referencing using the Call by Reference Node, I can't seem to access the temperature indicator (or wire it up so I can have the indicator in the main vi front panel).

 

Do you have any suggestions as to how I might be able to incorporate the temperature indicator in?

 

Thanks

0 Kudos
Message 7 of 17
(7,643 Views)
Add a temperature control the the front panel of the main VI, then convert it to a variant and wire it to the "data" input of the fitting VI. Inside the model, you can convert the variant back to the temperature.
0 Kudos
Message 8 of 17
(7,637 Views)

Oops, I just realised I was saying an indicator when in reality I did mean a control.

 

 

Thanks altenbach, I will give that a go now.

0 Kudos
Message 9 of 17
(7,613 Views)
So I have modified the main vi where I wire the temperature control to the "to variant.vi" and have then wired this to the 'data' input of the fitting vi (ie through the call by reference node).  In the fit function vi I then place a "variant to data.vi" on the block diagram and then wire the data terminal to the variant input.  I then wire from the data output on the "variant to data.vi" to the multiplication vi.  In order to set out what type of data I want outputted I connect up a DBL control to the type input.  I tried a few different set ups with the type input, but only this method gave me a set of unbroken wires.  However when I run this I get this error:  

Error 91 occurred at Variant To Data in Fit Function for DLVO and grav.vi->NI_Gmath.lvlib:LM call model function.vi:62->NI_Gmath.lvlib:LM function and gradient.vi:5->NI_Gmath.lvlib:LM abx.vi:4->NI_Gmath.lvlib:Nonlinear Curve Fit LM.vi:1->Non-linear fit to PE data.vi

Possible reason(s):

LabVIEW:  The data type of the variant is not compatible with the data type wired to the type input.

I think my problem is how is how I have set the data type in the "variant to data.vi", but not sure what else I can try.

I have attached the modified vi with the data I am fitting it to (see my first post for more details on the data file).
Message Edited by scottum on 06-02-2009 02:01 PM
0 Kudos
Message 10 of 17
(7,605 Views)