# Plot a 2D Region to Show Which Function is Bigger

Let us assume that we have two real functions $$f(x_1,x_2)$$ and $$g(x_1,x_2)$$.

I want to plot a 2D region of $$\{(x_1, x_2)| f(x_1, x_2) \geq g(x_1, x_2)\}$$.

The Region function seems cannot work well if f and g are complicated. Is there any suggested function in Mathematica to do this job?

It is quite difficult to understand what problems you faced, since you have not provided explicit code, so I am giving a very simple command just to get you started.

Assume the following functions

f[x1_][x2_] := x1^2 + 2*x2
g[x1_][x2_] := x1 + 2/x2


and then we can use

RegionPlot[f[x1][x2] >= g[x1][x2], {x1, 0, 4}, {x2, 0, 11}]


which returns a nice plot.

Another workaround that comes to mind is to use the Plot3D command. As an example

Plot3D[{f[x1][x2], g[x1][x2]}, {x1, -5, 5}, {x2, -10, 10},
PlotLegends -> "Expressions"]

• Thanks for your answer. But when f and g are rather complicated and computationally demanding, RegionPlot sometimes will generate unsatisfactory results. For example, some area which should be colored might become blank. May 5, 2021 at 0:57
f = x1 + x2*Sin[x1];
g = x1*x2 + Cos[x2]*x1;
ContourPlot[f - g, {x1, -10, 10}, {x2, -10, 10}, Contours -> {0},
ContourShading -> {None, Red}, PlotPoints -> 80]


• +1 Note that you get better resolution also using MaxRecursion rather than just using PlotPoints, e.g., PlotPoints -> 50, MaxRecursion -> 8 May 4, 2021 at 13:10
• That's a nice, nifty trick
– kcr
May 4, 2021 at 13:17
• @BobHanlon Thanks! MaxRecursion work. May 4, 2021 at 13:17