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: 

Can curve fit VI's handle piece-wise defined functions?

Solved!
Go to solution

I am trying to use the (Constrained) Nonlinear Curve Fit VI to analyze a step response.  Is it possible to define a parameter to fit a time shift?  That way I won't have to be so careful about getting the precise starting point of the analysis window.  E.g. y(t) = f(x(t-t0),a=[a0, at1]) or y(t) = f(x(t),a=[a0, a1, t0])?  It requires an IF (case statement) inside the function.  You can do this in Excel so I would have thought LabVIEW could do it, too.  See attached simplified example of a time-delayed linear fit.  It gives Error -20041 occurred at NI_Gmath.lvlib:Nonlinear Curve Fit LM.vi:1. Possible reason(s): Analysis: The system of equations cannot be solved because the input matrix is singular.

Regards,

Download All
0 Kudos
Message 1 of 7
(2,938 Views)

Hi

 

Thank you for contacting National Instruments, my name is Andrea and I’ll be assisting you with your issue.

 

I am going to check the vi that you have attached.

 

 

Regards,

0 Kudos
Message 2 of 7
(2,830 Views)

If you open the Nonlinear Curve Fit LM.vi and place some probes you find that the matrix fed to the Inverse Matrix.vi is:

 

1785  153  0

  153   20  0

    0     0    0

 

That matrix is produced by abx.vi.  The LM function and gradient.vi calculates the values of your function and the gradient.  The second column of the gradient is all 1s and the third column is all zeros. 

 

Perhaps this is a case where explicitly calculating the f'(X,a) in linearShift.vi might be worth a try.  Then you can assign suitable values at the discontinuity and avoid the singular matrix.

 

Lynn

0 Kudos
Message 3 of 7
(2,826 Views)

Your t0 paramter is quantized, thus the partial derivatives won't work (changing the parameter has no effect except for the few points where it jumps by one over an infinitesimal small increment).

 

You need to rewrite the formula so you get a smooth shift. Shouldn't be too hard.

0 Kudos
Message 4 of 7
(2,824 Views)
Solution
Accepted by topic author barkeram

Try this instead. Seems to work just fine. 😄

 

 

Message 5 of 7
(2,819 Views)

Thanks altenbach.  Your VI works.  Actually, after using yours as a reference, all you have to do to my original linearShift.vi is replace the Y[i] = X[i-n].vi with the subtract VI, and it works!  Not exactly sure why...  Your additional style improvements are also appreciated.

0 Kudos
Message 6 of 7
(2,793 Views)

Looking at the code again, you should also delete these two error local variables. You are writing to both error out terminals from different places with different information, so the final outcome is totally upredictable.

0 Kudos
Message 7 of 7
(2,783 Views)