LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to use levenberg marquardt vi

 Hi,

I am new to labview. I want to learn use of Levenberg Marquardt algorithm (Nonlinear curve fit.VI) to fit a simple polynomial. Can anyone show me how to use this vi.

In the attached prog in upper For loop I am generating a polynomial which I want to fit by another polynomial. I should get back almost same values of input parameters used in upper loop. 

Thanks in advance. 

 

0 Kudos
Message 1 of 10
(4,882 Views)

Read the detailed help for the Nonlinear Curve Fit.vi. It tells you that you need to create a VI from the template provided to calculate the values of the function. You wire  reference to that VI to the f(x,a) input.

 

Lynn

Message 2 of 10
(4,876 Views)

To fit a polynomial, you would use polynomial fit.

 

Looking at your code, you probably should start with some very basic LabVIEW tutorials.

 

  • You are randomly mixing datatytpes for no good reason at all (orange vs. blue).
  • Why are your control terminals inside the loop? Do you expect their values to change during the few nanoseconds it takes for the loops to execute? (if they would change, you would no longer have a polynomial, so place them before the loop!)
  • Why are the number of iterations different for the two loops?
  • You are simply creating two different polynomials, one with noise and one with more points. You cannot fit one with the other. What you can do is fit one to obtain the a,b,c used to generate it by only looking at the data. What you probably want to do is fit the noisy one, obtain the coefficients by fitting, then generate a smooth one using these coefficients.
  • In addition to the data array, you also need to generate an x array.
  • Wy is your graph the size of a postage stamp? Make it a bit larger to actually see the output.

Open the example finder and look at the fitting examples that ship with LabVIEW.

Do a search for levenberg-marquard here in the forum, there are tons of examples.

Message 3 of 10
(4,857 Views)

Non-linear fits (like L-M) are used when there is no linear set of equations that solve the Least Squares equations.  You can fit polynomials "linearly", which means there is an exact solution (coming from solving linear equations) rather than doing a non-linear fit that basically tries to approximate the solution.

 

Bob Schor

Message 4 of 10
(4,839 Views)

Thanks for your reply. I am completely new in Labview and really need some basic tutorials. Can you suggest me few such tutorials. I will use labview for coding and data acquisition later. 

0 Kudos
Message 5 of 10
(4,811 Views)

@nupurbiswas wrote:

I am completely new in Labview and really need some basic tutorials. Can you suggest me few such tutorials.


Start here

0 Kudos
Message 6 of 10
(4,796 Views)

@Bob_Schor wrote:

Non-linear fits (like L-M) are used when there is no linear set of equations that solve the Least Squares equations.

 


Fortunately, nonlinear fitting can be used for anything, at least as an exercise to learn about the technique ;). Using simple models takes the  potentially mathematically difficult parts ( (multiple local minima, ill posedness, etc.) out of the problem for testing. You could use it for a linear fit or even use it to calculate the average of an array by fitting it to a horizontal line. 😄

0 Kudos
Message 7 of 10
(4,790 Views)

True, you can use non-linear methods to solve linear problems.  But it might be useful to point out that while linear methods are (or should be) exact, non-linear methods are (and can be good) approximations to the solution.  Also linear methods (if available) are usually faster, as they (usually) require fewer function evaluations.  Makes no difference when fitting a second order polynomial to a few data points, but can become important when the number of points and parameters grows (consider a non-linear mean of 10,000 points)(hmm, if I know you, Christian, you've actually done this and can show that I'm full of Hot Air -- won't be the first time ...).

 

Bob Schor

0 Kudos
Message 8 of 10
(4,749 Views)

Well, I might be safe on this one.  I generated a million random numbers, then tried to fit Y = MX + B through it.  I used the Linear Fit method for one, the LM version for the other.  "Answer Analysis" says M should be 0 and B should be the mean (or close to it) (I used the index of the For loop for X, and Y was the LabVIEW (0, 1) random number generator).

 

Both Linear and Non-Linear versions gave the same answer for B (the Mean), 0.500248.  There was a slight difference in M (Linear was 4.17533E-10, LM was 4.17549E-10 -- I'm happy to agree they are the same, for all intents and purposes).

 

The Linear method took 23 milliseconds.  The LM method to 10.2 seconds.

 

Bob Schor

0 Kudos
Message 9 of 10
(4,733 Views)

Well, my suggestion to calculate the mean was to use a model of y=b. Then you also should implement explicit partial derivatives. 😄 Might get it to down to sub-seconds. 😮

0 Kudos
Message 10 of 10
(4,727 Views)