I am trying to plot the region over which a function of two (real) parameters a
and b
is real-valued, using RegionPlot
and MatchQ
. In general this will be a complicated function with real and complex parts, but to illustrate the query I will use a simple function, a^2 + b^2
:
RegionPlot[MatchQ[(a^2 + b^2), _Real],{a,-2,2},{b,-2,2}]
As expected, RegionPlot
colors the whole region. This is because RegionPlot
presumably evaluates its predicate - here MatchQ
- on the a,b mesh before plotting, so that the expression a^2+b^2
in MatchQ
is manifestly real, i.e. the Head
of the resulting expression is Real
and MatchQ
evaluates to True
. On its own however, with no contextual information on a
or b
,
MatchQ[(a^2 + b^2), _Real]
evaluates to
False
as expected. Now if I replace a^2+b^2
with
Evaluate[Expand[(a + I b) (a - I b)]]
i.e.
RegionPlot[MatchQ[Evaluate[Expand[(a + I b) (a - I b)]], _Real],{a,-2,2},{b,-2,2}]
RegionPlot
displays a completely blank region (also the case for ComplexExpand
). Since Evaluate
should have presumably overridden the HoldAll
attribute of RegionPlot
, I would have expected the expression to evaluate to Real
and therefore for the MatchQ
to evaluate to True
, so why doesn't RegionPlot
display the region in this case?
Evaluate
overrides onlyHold
-attributes of heads immediately enclosing it, but you have another layer here (MatchQ
). This discussion might help. $\endgroup$