I made a code which draws a plot of $5-x^2$ masked with a kind of rectangular function
in order to brake the branches of parabola at the points -1
and 1
and transform them into a vertical lines.
Clear["Global`*"]
rgbC = RGBColor[0.880722, 0.611041, 0.142051];
pltS = {rgbC};
f = 2 - Abs[Abs[-1 + x] - Abs[1 + x]];
(*triangular function with height 2 and base 2*)
lin = 2 -
Abs[2 x]; (*auxiliary function to make rectangular function of \
triangular function*)
k = FullSimplify[
lin/f]; (*rectangular function with height 1 and base 2, defined \
on intervals x[-1,1] and y[1,-\[Infinity]]*)
eq1 = x^4;
eq2 = 5 - x^2 + k - 1;
fPlt = {Plot[I*x, {x, -2, 2}, AspectRatio -> Automatic,
PlotRange -> {{-2, 2}, {0,
5}}]}; (*empty 'canvas' for applicating combined mPlt and uPlt*)
\
mPlt = {Plot[{eq1}, {x, -3, 3}, Method -> "BoundaryOffset" -> False,
AspectRatio -> Automatic, Filling -> Top,
FillingStyle -> LightBlue, PlotRange -> {0, 3}]};
uPlt = {Plot[{eq2}, {x, -1.1, 1.1}, Method -> "BoundaryOffset" -> False,
PlotStyle -> {pltS}, PlotRange -> {{-2, 2}, {3, 5}},
Filling -> Bottom, FillingStyle -> LightYellow]};
Show[fPlt, mPlt, uPlt]
The code works as expected when $x$ in uPlt
varies from -1.1
to 1.1
:
But things go curiouser when $x$ is bounded by -1
and 1
, the vertical lines disappear:
And it all becomes curiouser and curiouser with $x$ is ranging from -2
to 2
, now the only left "leg" is absent. The circumstances are aggravated by the error message 'infinite expression 1/0 encountered' popping:
Both legs are gowing back again with {x,-2,3}
or {x,-3,3}
and the error message persists.
What is going on?
fPlt
? Why notShow[mPlt, uPlt, AspectRatio -> Automatic, PlotRange -> {{-2, 2}, {0, 5}}]
? $\endgroup$ – Michael E2 Feb 20 at 21:32uPlt
. The function is:eq2 = 5 - x^2 + k - 1
wherek=(2 (-1 + Abs[x]))/(-2 + Abs[Abs[-1 + x] - Abs[1 + x]])
. The denominator of this is:(-2 + Abs[Abs[-1 + x] - Abs[1 + x]])
This is zero forx>=1
and the function is not defined. $\endgroup$ – Daniel Huber Feb 20 at 21:44fPlt
is a free, blank, vacant area where in I combine two plotsX^4
restricted by{y,0,3}
and5-x^2
restricted by{y,3,5}
which I do with different PlotRange for each plot. I can't use one Plot for both of them because of the different filling areas I need to paint. I agree it's stupid and unusual way to do it but I didn't find a better method. $\endgroup$ – Simpleton Jack Feb 20 at 21:45Abs[]
expression,ConditionalExpression
might be better suited to your purpose. For instance,Plot[ConditionalExpression[5 - x^2, -1 < x < 1], {x, -2, 2}]
$\endgroup$ – Michael E2 Feb 21 at 2:19