LabVIEW

cancel
Showing results forΒ 
Search instead forΒ 
Did you mean:Β 

3D Polynomial Fit

I posted a thread regarding this earlier but it's getting a bit long so I thought I would start a new one (sorry mods).

Anyway, basically I have 3 2D arrays and I need to do a 3D polynomial fit and find the equation for the surface.

I found an example here:

http://sine.ni.com/apps/we/niepd_web_display.display_epd4?p_guid=B123AE0CBB3C111EE034080020E74861&p_node=DZ53022&p_source=external

(In 7.1, thanx Christian for converting it to 6.1).

The example vi takes in 3 1D arrays. I changed the program so it takes 2D arrays and index them into 1D arrays instead.

The variables are
X = reflectivitiy (basically this 2D array has same numbers across the row, different numbers at each row).
Y= WR
Z= WW

How indexing works:
2 2
5 5
3 3

get
2
2
5
5
3
3

The program would then give me an equation of z = a + bx + cy + dx^2 + exy + fy^2 + ....
I also fitted Y vs Z using 2D polynomial fit for different reflectivity values and obtained an equation of z= a +by + cy^2 + ...

After substituting x into the 1st equation and compare the 2 equations above the two aren't even anywhere close. I then tried fitting only 1 reflectivity and the 3D polynomial fit gave me a result with ~7.3% error (kinda big but ok for now).

I then tried arranging the 2D arrays so I get something like:
2
5
3
2
5
3
instead. But again this doesn't work. 😞

I've tried trancing through the example vi algorithm but the math seems a bit wierd for me. I've also tried looking around on the web but didn't find anything particularly useful. 😞

Any helps would be appreciated. Thanx.
0 Kudos
Message 1 of 3
(3,637 Views)
Well, I plugged your xls data into my version of the code and I agree the fit is not great. It seems that a 2D polynomial without cross terms is insufficient to describe your data. Your model is not appropriate.

The attached adaptdation (LabVIEW 6.1) compares a 2D fit (default poly order 4) with 5 simple 1D polynomial fits, one for each slice. As you can see, each slice needs different coefficients and the fits are pretty good. There is no global set of coefficients that can fit all at once in 2D very well.

I did not bother to reshape the inputs and outputs to 2D, it is irrelevant for the fit. Also the order of points should be irrelevant for this algorithm.

Let me know if this makes sense. πŸ™‚

If you just need interpolated data (no formula) for anywhere on the 2D space, you could do it in two steps. First interpolate each slice as above, pick the interpolated value of each slice at the desired position, then do a second polynomial fit in the second dimension.
0 Kudos
Message 2 of 3
(3,629 Views)
Thanx for the help. I tried using the program and it seemed to work pretty nicely. I then tried analyzing the results. First I tried finding the 2D polynomial constants for 2% reflectivity. Then I tried finding the 3D polynomial constants, plug in 2 for X. Finally I tried plugging X/Y and analyze the % error.

It seems that 2D polynomial fit is pretty accurate while 3D polynomial fit seems to have large errors. 😞

Maybe this is because of the missing cross terms? Hmmm.... (*thinking*)
0 Kudos
Message 3 of 3
(3,617 Views)