08-30-2015 09:44 AM
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.
08-30-2015 09:57 AM
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
08-30-2015 12:21 PM - edited 08-30-2015 12:23 PM
To fit a polynomial, you would use polynomial fit.
Looking at your code, you probably should start with some very basic LabVIEW tutorials.
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.
08-30-2015 03:50 PM
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
08-30-2015 11:19 PM
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.
08-31-2015 12:54 AM
@nupurbiswas wrote:
I am completely new in Labview and really need some basic tutorials. Can you suggest me few such tutorials.
08-31-2015 01:02 AM
@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. 😄
08-31-2015 04:14 PM
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
08-31-2015 04:59 PM
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
08-31-2015 05:02 PM
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. 😮