1
$\begingroup$

The following code

Block[
  {ifun1, values},
  ifun1 = Interpolation[
    {{{0.0, 0.0}, 0.0}, {{0.0, 1.0}, 0.1},
     {{1.0, 0.0}, 0.2}, {{1.0, 1.0}, 1.0}},
    InterpolationOrder -> 1, Method -> "Spline"
    ];
  Print[ContourPlot[ifun1[x, y], {x, 0, 1}, {y, 0, 1}]];
];

produces this contour plot

enter image description here

why are the contours smooth? I would expect Mathematica to pick particular grid triangles in the interpolation and was expecting to see those.

$\endgroup$
8
  • $\begingroup$ Hint: ContourPlot[x y, {x, 0, 1}, {y, 0, 1}] $\endgroup$ Commented Nov 10, 2025 at 11:12
  • 4
    $\begingroup$ In case you didn't know, InterpolationOrder -> 1 means the interpolants will be linear in each variable — bilinear in this case — not a linear polynomial. $\endgroup$ Commented Nov 10, 2025 at 11:18
  • $\begingroup$ @xzczd, I don't get it. Shouldn't Mathematica use triangles (say) {{0,0},{1,0},{0,1}} and {{1,0},{0,1},{1,1}} for interpolation on those planes? (the other alternative being picking {0,0}<->{1,1} as the border, rather than {1,0}<->{0,1} as above) $\endgroup$ Commented Nov 10, 2025 at 11:22
  • 2
    $\begingroup$ Perhaps ifun1 = {{{0.0, 0.0}, 0.0}, {{0.0, 1.0}, 0.1}, {{1.0, 0.0}, 0.2}, {{1.0, 1.0}, 1.0}} // NDSolve`FEM`ElementMeshInterpolation[{NDSolve`FEM`ToElementMesh[#[[All, 1]]]}, #[[All, 2]]] &;? $\endgroup$ Commented Nov 10, 2025 at 11:22
  • 1
    $\begingroup$ And actually Method -> "Spline" only works for regular grid, and your test sample happens to form a regular grid. If it's not, for example: Block[{ifun1, values}, ifun1 = Interpolation[{{{10^-6 + 0.0, 0.0}, 0.0}, {{0.0, 1}, 0.1}, {{1.0, 0.0}, 0.2}, {{1.0, 1.0}, 1.0}}]; ContourPlot[ifun1[x, y], {x, 0, 1}, {y, 0, 1}]] Interpolation automatically turns to the unstructured method and you get an unsmooth result. $\endgroup$ Commented Nov 10, 2025 at 11:30

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.