Showing results for 
Search instead for 
Did you mean: 

User defined high degree polynomial fit (surface fitting)

Go to solution

when we get data from the measurement ,we always meet the situation that the result value Z is related to 2 Independent Variable ,actually it likes 3D surface .

the formula always like :Z=F(X,Y).

I checked the  polynomial fit express vi on labview , but i still can not find a solution to built an complicated user-defined polynomial and get the coefficient.


for example ,i can defined a simple polynomial and let the X,Y,Z to fit as this polynomial ,then get coefficients.

this picture shows my defined polynomial Z=c0+c1*X+C2*X^2+C3*X^3+C4*X^4+C5*X^5+C00*Y+C01*Y^2+C02*Y^3

but the coefficient come form the every different degree formula ,then if i want to define a polynomial like :




HOW CAN I TO  DEFINE this polynomial and fit as least square method ?

Thanks ,



0 Kudos
Message 1 of 15

i really need to get the coefficient after fitting !

0 Kudos
Message 2 of 15

Can you attach your actual VI?

0 Kudos
Message 3 of 15

thank you for your reply , actually i learned this method from here ,named:"9P interpolacija" ,i also attached it ,i downloaded it from here .

it's very normal to calculate the value by least square method in industry  ,for example :when you measure  the concentration of liquid via the  speed of sound  principle ,the concentration are  related to the speed of sound and temperature .so,the Z  is concentration and X is speed of sound ,Y is temperature .

sometimes ,you need to find a best model of surface to describe this relation .so you need to test different model of polynomial .

that is the reason why i need the coefficient .


thanks again 

Download All
0 Kudos
Message 4 of 15

Your VI does not contain any data. Please attach some reasonable xyz data to be fit.


(I cannot open your VI on english Windows unless I rename the file. Please use regular file names).


There are probably better ways to create the H Matrix than with a formula node. That 9P example looks overly complicated. But yes, you'll get the least square fit and coefficients out of it at the end.

0 Kudos
Message 5 of 15

thank you for you reply

here i make a modification on my vi ,thank you for your help kindly .

0 Kudos
Message 6 of 15
Accepted by fyang2017

Maybe something like this?


(Please double-check the math for the H matrix.)



Download All
Message 7 of 15

Thank you  very very much ,this is really good solution for this kind of formula .i start to understanding the matrix in labview  via this example ,thanks  again.


i try to draw  a 3D surface by this data ,but the surface looks very strange !


0 Kudos
Message 8 of 15

The H matrix won't give you any interesting surface. What you need to do is generate a xy grid that covers a similar range (in x and y) as the input data and is spaced sufficiently to show all the details, then calculate Z for each grid point. Overlay it over the real data.

0 Kudos
Message 9 of 15

I quickly modified one of my ancient VIs to show the general procedure. See if this works for you.

(This is using the old actvieX 3D graphs. Should be easy to adapt to the new versions)


(Note that SVD has problems. You need to use a different algorithm, such as LU decomposition)





Download All
0 Kudos
Message 10 of 15