0
$\begingroup$

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.

Thanking you in advance.

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}]
$\endgroup$
  • 1
    $\begingroup$ You can use RegionFunction to restrict the region that is drawn $\endgroup$ – Niki Estner Apr 24 '18 at 10:10
  • $\begingroup$ 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... $\endgroup$ – José Antonio Díaz Navas Apr 24 '18 at 10:39
  • 1
    $\begingroup$ should point 5 be {0, 0.4} ? $\endgroup$ – george2079 Apr 24 '18 at 18:59
1
$\begingroup$

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}] &)]

enter image description here

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

$\endgroup$
  • $\begingroup$ You can also do it with ContourPlot[A[x, y], {x, y} ∈ A["ElementMesh"]] $\endgroup$ – Michael E2 May 24 '18 at 19:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.