LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Lev-Mar problem

Solved!
Go to solution

Im tryng to do a fitting for parabolic equation (y= ax^2 + bx + c ) for data 2. But i couldnt make the the Lev-mar fitting to function. Please help me.

Download All
0 Kudos
Message 1 of 11
(3,927 Views)

Have you studied the examples that ship with LabVIEW?  The two examples using Gaussians (Gaussian surface with offset fit.vi and Sum of three Gaussians with offset fit.vi) use Levenberg-Marquardt and may provide additional insight.

 

Bob Schor

Message 2 of 11
(3,917 Views)

You don't need lev-mar for this. it is a simple polynomial, so fit it to one.

 

Your mistake is that you wire from after the feedback node to the fitting VI, thus you won't have any data on the first iteration, and since you apparently use "continuous run", you'll never get anything because the feedback node reinitilzies every time the VI restarts.

 

Once you fix all that and use initial values of 1,1,1, the result of lev-mar is -19.569, -0.0209, 72.556, the same as you would get using polynomial fit (which does not require intitial guesses or manual models and is thus much better).

 

 

Message 3 of 11
(3,894 Views)

thanks for the insight. But im totally lost here. could you attached the VI file you made from the screenshot you posted?

that will mean a lot to me.

0 Kudos
Message 4 of 11
(3,872 Views)

Did you understand my first two paragraphs?

0 Kudos
Message 5 of 11
(3,867 Views)

i did try using polynomial but it cant do the fitting for the data.

 

and im lost at the second paragraph.

0 Kudos
Message 6 of 11
(3,861 Views)
Solution
Accepted by topic author Nusnus

@Nusnus wrote:

i did try using polynomial but it cant do the fitting for the data.

 

and im lost at the second paragraph.


There are a few ways to do the polynomial fitting right and million ways to do it wrong. Unless you show us what you tried, we cannot tell what you are doing wrong.

 

Do you have problem with the math or with LabVIEW itself?

 

In any case, maybe the following (LabVIEW 2013) can give you some ideas. (... and please don't use "continuous run" mode)

Message 7 of 11
(3,850 Views)

Thank You so much. now i see where it went wrong. The countinuos made the fitting encountered errors. your example is really helping.

 

extra question. does it mean i cant do the fitting with the vi program that always in loop/continuos?

 

Thanks again. cheers

0 Kudos
Message 8 of 11
(3,789 Views)

@Nusnus wrote:

 

extra question. does it mean i cant do the fitting with the vi program that always in loop/continuos?

 


Of course you can! You should incorporate the entire code into a larger program that fits on demand or whenever one of the inputs or data changes. It is not necessary to repeat the same calculation with the same inputs over and over, millions of times per second. The result will not change, so once is enough!

 

Do some LabVIEW tutorials. Look at the event structure, look at state machine architecture.

 

Create a toplevel VI with a nice user interface that is always running and allows you to load new data and adjust settings, and that will automatically re-fit whenever needed, but idly waits for input when nothing new needs to be done. The CPU use should be near zero most of the time.

 


@Nusnus wrote:

The countinuos made the fitting encountered errors.

 


The error was mostly due to the fact that you were tapping into the data after the feedback node instead of branching before it. You were operating on data that was one iteration older, but since you just restarted the program, there was nothing there. The "continuous run" is a temporary debugging tool for subVIs, not a sane way to operate a topelvel program.

Message 9 of 11
(3,765 Views)

Bonus task:

 

Your data seems to be centered and symmetric around x=0 and thus the linear term is approximately zero. Thus you could fit with an even simpler model that only includes the offset and quadratic term. Even that can be done directly using general linear fit. You would just create the H matrix that omits the linear term and you would get the solution to y(x) = ax² + b. Try it!

 

You really should not use levenberg-marquardt for any of this. That should be reserved for nonlinear models. Your model is linear in the parameters and the presence of x² deos not change that.

Message 10 of 11
(3,762 Views)