cubic spline interpolation of a function that yields NaNs when evaluated at some of the grid points.

6 views (last 30 days)
Hi i want to cubic spline interpolate an unknown function defined over a 3 dimensional domain, whose values i know at the gridpoints of some 3D grid. This can conveniently be done with griddedinterpolant, which even allows extrapolation.
Yet my unknown function is not defined on a part of the grid, hence it takes the value NaN at some gridpoints, like:
4 3 2 1
3 2 1 NaN
2 1 NaN NaN
1 NaN NaN NaN
If i now use griddedinterpolant, the interpolant gives NaN, whether inside or outside the boundaries of the grid.
Is there some way to overcome this problem? Is there a way to get a cubic spline interpolation for a function that yields NaNs on some parts of the grid, on which the interpolant is defined?
Any advice is greatly appreciated!

Answers (3)

Image Analyst
Image Analyst on 29 Jun 2013
You're not going to be using coordinates down there anyway - you can't since you don't know what they are - so just set them to anything, such as 1, and do your spline. It doesn't really matter what you do down there. Now if you needed to extrapolate into the nan zone, that's a different question. I might use John DÉrrico's polyfitn() to do that. (See the File Exchange).

dominik
dominik on 29 Jun 2013
Edited: dominik on 29 Jun 2013
Thanks for ur tips!
I thought about doing that (putting an arbitrary number in place of the NaNs), but was recluctant to do so because if I assume some value instead of NaN, the interpolant for values close to the "NaN boarder" will be influenced by my arbitrary choice. Furthermore it would be nice if i could extrapolate a little in the area between the NaNs and the first values, where the function is still defined (in the above example e.g. at 0.5).
I have not used polyfitn yet. What i did check out is to use the curve fitting tool on a 2D subsection of the 3D grid. As my function is zero almost everywhere and goes towards infinity when getting closer to the NaN boarder i had hoped to get a better fit with an interpolant.
In fact i noted that the curve fitting tool seems to allow for cubic spline interpolation with the NaNs. At least inside the non NaN region of the grid i can evaluate the interpolant i f created this way (unlike gridded interpolant). If I could use this in 3D that would give me a nice approximation within the non NaN region. With a fine enough grid for the unknown function that would probably already be good enough for my application...

dominik
dominik on 30 Jun 2013
Edited: dominik on 30 Jun 2013
Update:
I have above described the behavior of griddedinterpolant wrongly. I found that cubic interpolation is possible within any cube that does not contain NaN and is not neigbouring another cube that contains a NaN. (By "contain NaN" i mean that the function evaluated at the 8 corners of the cube around the interpolation point is never NaN.)
Yet, if the cubic interpolant is created with the curve fitting toolbox (which unfortulatley only allows for with 2D data), the behavior is a bit different: I found that cubic interpolation is possible within any rectangle that does not contain NaN (the neigbouring rectangle dont matter).
Hence the curve fitting interpolant allows to go closer to the boarder then the griddedinterpolant. (They behave equally for linear intepolation). But unfortunatley - at least in my application the curvature of the interpolant goes crazy in the square close at the NaN boarder.

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!