2

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!

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
user27119
  • 2,500
  • 13
  • 34
  • how do you want to represent the infinite value of the function for $x<0$? – glS Jan 02 '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. – user27119 Jan 02 '16 at 14:23

2 Answers2

3

Piecewise is built for exactly this purpose:

With[{a = 2, inf = 100},
 Plot[
  Piecewise[
   {
    {inf, x < 0},
    {a x, x > 0}
    }
   ],
  {x, -2, 2}
  ]
 ]
glS
  • 7,623
  • 1
  • 21
  • 61
3
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

eldo
  • 67,911
  • 5
  • 60
  • 168