LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

General Polynomial fitting of a 5 points curve

Solved!
Go to solution

Hi, I'm currently trying to fit a curve of only 5 points with the general polynomial fitting function but it doesn't seem to work. I tried all the algorithms and orders up to 5 (the number of points). Have you got any solution to get wonderfull fits that we get with excel ?

 

POLYNOMIAL-FIT.JPG

0 Kudos
Message 1 of 8
(5,519 Views)

If you have N points you can fit to a polynomial of order up to N-1. When using order N-1 the polynomial should exactly go through all of the points.

Can you show your code?

 

Message 2 of 8
(5,505 Views)

It is possible that your data is ill conditioned.

 

Your x-values are offset far from zero and only cover a very small range. Have you tried to rescale x, e.g. subtract the average x from all values to see if things improve?

0 Kudos
Message 3 of 8
(5,500 Views)

Hi, I've been an idiot, the fit was made of five points, the lines between each points was just a linear interpolation made by the software.
Now, I have a real, serious problem, still with this polynomial fitting. The fitting seem to work properly but then when I use the curve coefficients to remake the curve by my own, the curve is negative and has nothing to do with the fit. Here are pictures of the front pannel and of the block diagram of my program, have  you got any solution ? I've been using as well as the curve fitting express vi, the general polynomial fitting VI but it's been doing exactly the same thing...

 
Thanks a lot 😉

 

David

 

POLYNOMIAL-FIT.JPG

Front pannel - left diagram =  curve fitting that works properly & right diagram = for the same curve coefficients and X values the curve fit is way too far from the original curve to fit.

 

POLYNOMIAL-FIT2.JPG

Block diagram of this part of the program

0 Kudos
Message 4 of 8
(5,480 Views)
Solution
Accepted by topic author David F

I think you're using the coefficients in the wrong order. If the coefficient array is a, the formula is:

y = a0 + a1*x + a2*x^2 + ...

 

Or as you label them, element 0 is e, element 1 is d, ...

 

Hope this helps,

Daniel

 

0 Kudos
Message 5 of 8
(5,463 Views)
Yep that's why it wasn't working ! 😉 thanks a lot !
0 Kudos
Message 6 of 8
(5,461 Views)
No need for that formula node. Simply wire the coefficients array and x array into "polynomial evaluation". 🙂
0 Kudos
Message 7 of 8
(5,450 Views)

A few comments to your code. about 80% of your code in unecessary and in the style of Rube Goldberg.

 

  • Index array is resizeable, so you only need one instance.
  • Use "array subset" to get an array subset, no need for two "split array" in a row.
  • Use the polynomial fit form the fitting palette, no need for express VIs and dynamic data.
  • Use polynomial evaluation instead of all that mess at the bottom.
  • Make the code scaleable. If you follow the above advice, it automatically will be.

 

Scaleability is important. Your code would need to be rewritten whenever you want a different polynomial order. If you follow my suggestion, all you need to change is the "polynomial order" input and everything else can stay as is. Try it!

 

If you need more detailed suggestions, please you attach your VI?

0 Kudos
Message 8 of 8
(5,448 Views)