LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Error -20003 when using Nonlinear Fitting function

Hello,

When I attempt to fit data that comes in live through a spectrometer using the nonlinear fitting function, I get Error -20003, which states that "the number of samples must be >0" as the possible reason for the error. What is this implying that I am doing wrong, and how can I fix it?

I've attached the code that I am working on. The fitting is under the true case of the top case structure. 

Download All
0 Kudos
Message 1 of 7
(951 Views)

I don't have access to LabVIEW 2022 at them moment. can you "save for previous..LabVIEW 2020 or lower" and attach again??

 

How does the data look like? What fitting functions do you use?

0 Kudos
Message 2 of 7
(924 Views)

I believe I saved them in a way that you should be able to access the VIs now.

 

The data generated is supposed to resemble a decaying sinusoid. As far as the fitting equation goes, there's a lot to it. I've attached all three of the references used. Basically, equations from Table 7-2 in the "low-loss medium" and "good conductor" columns are used first, then the reflection coefficients for perpendicular and parallel polarizations are calculated from Table 9-2 and averaged. Then the "Gamma in" is calculated from the other source, and squared as per Table 9-2. 

I think the problem is not so much in the equation as it is in my guess for a (which is "d", thickness in these equations), so don't worry about studying the equations in too much depth.

0 Kudos
Message 3 of 7
(913 Views)

You need to get rid of the race conditions caused by blatant overuse of local variables. For example why are none of your terminals in the model connected??? There is no way to tell that the e.g. the various locals for [x] are read only after the control [x] has been updated. Connect the terminals and eliminate the locals!

 

None of your sequences are needed in the caller if you would use proper dataflow. You have the "wavelength" data right there, so why not branch the wire to the various places were they are needed instead of reading from five (five!!!) local variables of same? Why are you calling the model by reference if you never even look at the output?

Another race condition is where you write the "absorption coefficient" in parallel to reading its local variable. Some of your locals are read even if they never get written, depending on the state of the "mode" (which should probably be an enum, not a combo box.)

 

That "select" and wired constants is just a "NOT", right? There are primitive for e^x, 1/x and (-1)x, no need to jump through all these flaming hoops.

 

Your initial parameter guesses is an empty array, It need to match the array size the number of parameters used in the model and contain reasonable parameter guesses in the right order..

 

This is all just the tip of the iceberg!

 

We don't have any of your subVIs, instrument, or data to really test anything. Can you boil it down to a small example containing a typical wavelength and spectrum arrays as diagram constants? Then we can at least test your model.

 

0 Kudos
Message 4 of 7
(898 Views)

Hi, thank you for taking time to look at my code.

I am aware that there are other parts that could be made better. I inherited a lot of this code and did not write that part myself. I was planning on fixing it up once the fitting became functional. I made the local variable changes you suggested.

Rather than complicating the issue with my big code, I made a small example that has the same issue. I still think that my initial condition has something to do with the problem, though I created one initial condition to match my one parameter a. I would appreciate it if you don't mind looking at this simple VI I created, which is pretty much a linear equation, just using the nonlinear fitting format because that is what I am struggling with.

Download All
0 Kudos
Message 5 of 7
(845 Views)

You are missing some basic understanding of array operations. If you multiply two 1D arrays, it will be element by element. Your model just multiplies the array of parameters with the array of x values, but since there is only one parameter the shorter array wins and the output will only have one element.

 

If you want to multiply each x element by the first array element of the parameters, you need to index that out first.

 

altenbach_0-1689082931827.png

 

Now everything seems to work just fine:

 

altenbach_1-1689083159231.png

 

 

(Please, (please!!!) don't maximize all your diagram and front panels to the screen. That's very annoying!)

 

Message 6 of 7
(839 Views)

Thank you very much for that simple fix. I will try to apply it to my larger code as well.

0 Kudos
Message 7 of 7
(837 Views)