07-07-2016 08:16 AM
You have the data. Look at the grid of points, and try to imagine a surface going through the points. Does the surface "look like a plane"? Then fit a plane. Does it look like a piece of paper you'd hold by the edges and curve in one dimension? That can be approximated as a second-order polynomial "translated" in a straight line. Does it look like it might be a surface of a sphere or ellipse? That's one form of a second-order polynomial in x and y. Does it smoothly increase in one direction and decrease in the other? That may be a hyperboloid, another form of second-order polynomial.
If there are more than one max/min to the data, you might have a third-degree polynomial. If you are making a model based on no "other" data (like a deep understanding of the physical/chemical interactions), simpler models are often "safer". Through N points you can exactly fit an N-1 order polynomial, but what does that tell you? [Not much more than saying "My model says the first point will be 1.23, the second 4.36, ..."].
Bob Schor
07-07-2016 10:02 AM - edited 07-07-2016 03:42 PM
So if you want to make a 2D polynomianl fit or arbitrary order, you need to rearrange the data so it only contains valid points (i.e. where z is not NaN).
For all valid data points, create corresponding 1D arrays of all x, all y, and all z (or a 2D array with these three columns or rows), then do something similar to my old code here. I have even included the funtion to calculate Z for any arbitrary x,y, pair.
Note that you need to implement a check that tells you if the xy combination is in the valid region.and return NaN otherwise.
Sorry, the code is a bit old.
07-07-2016 11:08 AM
Thanks everyone for their input. The suggestions helped me think through the problem and I have come up with a solution that appears to work for me.
One of the main issues I had was not having a good understanding of the interpolation function. The NaN value was causing the bicubic spline option to fail. When I used a dataset that had no NaN values this mode gave me the values within the error I could accept. The bilinear mode worked well also when the NaN values were removed.
Now what I need to do, as altenbach suggested, is make subsets of my data that has data for the pressure and temperature that I am working with and excludes NaN values.
Terry
07-07-2016 05:15 PM
Here's a simple modification of my earlier VI, but using your data. An eight order polynomial is overkill, but fits the data perfectly.
I have not implemented the input bounds checking, but it should be easy to add.
07-08-2016 12:11 PM
The NaN bound as a function of temperature is almost linear, so you can easily test if you are outside the valid region and substitue NaN when evaluating Z(x,y).