LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Curve fit with 2 independent variables

Solved!
Go to solution

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

0 Kudos
Message 11 of 15
(2,012 Views)
Solution
Accepted by RavensFan

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.

 

 

 

Message 12 of 15
(2,002 Views)

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

 

 

0 Kudos
Message 13 of 15
(1,991 Views)

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.

0 Kudos
Message 14 of 15
(1,958 Views)

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).

0 Kudos
Message 15 of 15
(1,933 Views)