# Loop command in Interpolation

I have a following interpolation function A[x,y] defined below. The variable y has some fixed range which is different for each x. Now, while doing interpolation and further making a contour plot Mathematica is not restricting the bound of y given in interpolation command, rather it is maximizing the range of y for all x, e.g., maximum allowed value of y is 0.76 for x=0, while it is 0.7442 for x=0.2. How, I can make a contour plot with different maximum value for y for each individual x.

ClearAll;
A := Interpolation[{{{0, 0}, 84.82}, {{0, 0.1}, 84.53}, {{0, 0.2},
83.68}, {{0, 0.3}, 82.22}, {{0, 4}, 80.12}, {{0, 0.5},
77.28}, {{0, 0.6}, 73.58}, {{0, 0.7}, 68.7}, {{0, 0.76},
64.2}, {{0.2, 0.0}, 84.63}, {{0.2, 0.1}, 84.3}, {{0.2, 0.2},
83.4}, {{0.2, 0.3}, 81.9}, {{0.2, 0.4}, 79.86}, {{0.2, 0.5},
76.9}, {{0.2, 0.6}, 73.16}, {{0.2, 0.7}, 68.05}, {{0.2, 0.7442},
65.12}, {{0.5, 0.0}, 83.56}, {{0.5, 0.1}, 83.25}, {{0.5, 0.2},
82.3}, {{0.5, 0.3}, 80.70}, {{0.5, 0.4}, 78.32}, {{0.5, 0.5},
74.9}, {{0.5, 0.6}, 70.0}, {{0.5, 0.61}, 68.6637}},
InterpolationOrder -> 3]

A[0.5, 0.4]

ContourPlot[A[x, y], {x, 0, 0.5}, {y, 0, 0.7}]

• You can use RegionFunction to restrict the region that is drawn Commented Apr 24, 2018 at 10:10
• InterpolationgFunction gives you the valid domain for x and y variables. In your case, this is {{0,0.5},{0,0.4}}, so MMA extrapolates beyond these values if you increase the plotting domain...I would use ContourPlot[A[x, y], {x, 0, 0.5}, {y, 0, 0.4}], or as @NikiEstner suggest... Commented Apr 24, 2018 at 10:39
• should point 5 be {0, 0.4} ? Commented Apr 24, 2018 at 18:59

extract the convex hull of the grid points from the interpolation function:

   ch = ConvexHullMesh[A["Grid"]];


use as region function:

   ContourPlot[A[x, y], {x, 0, 1}, {y, 0, 1},
RegionFunction :> (RegionMember[ch, {#1, #2}] &)]


Note I fixed that point from 4 to .4 per comment.

• You can also do it with ContourPlot[A[x, y], {x, y} ∈ A["ElementMesh"]] Commented May 24, 2018 at 19:52