# Plotting a function defined to be infinite over a sub-domain [duplicate]

This question already has an answer here:

I'm trying to plot the following function with the constraints shown,

$$f(x)=\begin{cases} \infty \quad x<0 \\ A\,x\quad x\ge 0 \end{cases}$$

However I can't work out how to show this in Mathematica, I tried using RegionPlot[] but it doesn't seem to work (or I'm missing something!). The other way I thought of would be to plot as two separate functions and then use Show[].

If someone has a smarter way that would be helpful!

## marked as duplicate by Artes, MarcoB, Bob Hanlon, Jens, Yves KlettJan 5 '16 at 1:13

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

• how do you want to represent the infinite value of the function for $x<0$? – glS Jan 2 '16 at 14:21
• On the plot it would just have to 'look' large. In reality I would just set to a high value and tweak the plot range. – Q.P. Jan 2 '16 at 14:23

## 2 Answers

Piecewise is built for exactly this purpose:

With[{a = 2, inf = 100},
Plot[
Piecewise[
{
{inf, x < 0},
{a x, x > 0}
}
],
{x, -2, 2}
]
]

Plot[Piecewise[{{2.0, x < 0}, {x^2, x > 0}}], {x, -1, 1},
PlotRange -> {Automatic, {0, 2}},
MeshFunctions -> {#2 &},
Mesh -> {{2, 0}},
MeshStyle -> None,
MeshShading -> {Dashed, Automatic},
Ticks -> {Automatic, {1, {2, \[Infinity]}}},
TicksStyle -> Directive["Label", 14]]


• This is also a great solution, thanks for the contribution! – Q.P. Jan 6 '16 at 21:41