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 Klett Jan 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.

  • $\begingroup$ how do you want to represent the infinite value of the function for $x<0$? $\endgroup$ – glS Jan 2 '16 at 14:21
  • $\begingroup$ 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. $\endgroup$ – Q.P. Jan 2 '16 at 14:23

Piecewise is built for exactly this purpose:

With[{a = 2, inf = 100},
    {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]]

enter image description here

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

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