Bug introduced in 10.0 and fixed in 10.1
Context
I am trying to identify contours of a function which is sampled on a cartesian grid within an irregular (triangular) region.
Here is the data
tab = ReadList[
"https://dl.dropboxusercontent.com/u/659996/tabOmega1.txt"] //
Flatten[#, 1] &;
It looks like this:
Map[Point, Map[Most, tab], 1] // Graphics
g3 = ListPointPlot3D[tab , PlotRange -> Full]
Now Mathematica (v10.0.2) happily makes contours of it:
g = ListContourPlot[tab , PlotRange -> Full]
But if I try to produce an interpolation function out of it
tabint = tab /. {rp_, ra_, v_} -> {{rp, ra}, v};
func = Interpolation[tabint, InterpolationOrder -> All];
It produces unrealistic numbers
func[1, 2]
(* 37.9231 *)
Indeed the interpolation is completely off:
Plot3D[func[x, y], {x, y} ∈ dg]
Question
How can I get Mathematica to interpolate properly though this evenly sampled data on an irregular region?
Attempt
Following this post
I can use
func = Nearest[{#, #2} -> #3 & @@@ tab];
ContourPlot[func[{x, y}], {x, 0, 4}, {y, x, 4}]
but the contours are irregular because the interpolation is piecewise constant, as can be seen on this zoom:
ContourPlot[func[{x, y}], {x, 0, 1}, {y, x, 1}]
An alternative may involve something new in version 10 like
dg = g // DiscretizeGraphics;
Update
Intriguingly the following code seems to work
dat = {#[[1]], #[[2]],
If[#[[1]] < #[[2]], Sin[5 #[[1]] #[[2]]], 0]} & /@
RandomReal[1, {2000, 2}];
if = Interpolation[dat, InterpolationOrder -> 1];
ContourPlot[if[x, y], {x, 0, 1}, {y, 0, 1}, Contours -> 25]
This would suggest there is something wrong with the tab
grid but it is not obvious what exactly?
InterpolationOrder -> 1
I get "The element mesh has insufficient quality". I wonder if this is related to the fact that your grid is in fact regular. In v9 I don't get this, and there should be no problem. I would report this particular problem (Interpolation[tab, InterpolationOrder -> 1]
) to support. As a workaround you could either try rolling your own linear interpolation (start with DelaunayMesh to break it into triangles then interpolate over each triagle), or exploiting the fact that your grid is a regular square grid ... $\endgroup$