From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Error -20041 Nonlinear curve fit

I am trying to write a program that will compute the nonlinear best curve fit based on data previously collected.  The part that I am having trouble with is I keep recieving error -20041 determinate is 0.  I put in two arrays to see if the problem was that the data was not getting passed in correctly, however the arrays are coming in correctly so that is not the problem.  It is possible that my initial guesses are incorrect, however they are pretty close to what they should be, so I don't believe that is the problem.  Any help is greatly appreciated.  Attached is my program, as well as a screenshot of my initial guesses.

Download All
0 Kudos
Message 1 of 3
(2,921 Views)

Your initial parameters are far from appropriate values. When I plot the formula you want to fit with the x data the graph does not remotely resemble the data graph.  Altenbach asked about this in your other thread.

 

Default formula.png

 

Note the orders of magnitude difference in the Y-axes.

 

I looked at the formula and saw that to get a peak the value of a1 had to be between 300 and 400.  Then I ddjsuted the other parameters until the curve began to resemble the data.

 

better initial params.png

 

Again, as altenbach suggested, I switched to using a VI to calculate the model function.  When I ran it that way, I got an error stating that the maximum number of iterations had been exceeded. On your VI you had set the termination parameters to 1 iteration maximum and tolerance of 1E-14.  Considering that Lev-Mar is an iterative process and that your data has ~2% noise and the peak is not really symmetric, those values guarantee that it will never find a solution. I changed maximum iterations to 100 and tolerance to 1E-4.  It converged and produced the result shown below.

 

Good fit.png

 

The model function VI looks like this.  See the Detailed help for Lev-Mar for information about creating this VI.

 

Model function VI.png

 

Lynn

0 Kudos
Message 2 of 3
(2,893 Views)

@johnsold wrote:

 

Model function VI.png


I would delete the FOR loop. Less clutter... 😄

0 Kudos
Message 3 of 3
(2,878 Views)