1

I'm trying to enter a piecewise function (named eq30) into Mathematica. However, it seems not to work. The expression I entered is

eq30 = gr[x] == Piecewise[{{x, x > 1}, {0, x <= 0}}]

But, when I try to plot the equation as...

Plot[eq30, {x, -5, 5}]

It gives me an empty coordinate plane. Also, the eq30 doesn't turn blue, as do my other 29 equations when I enter them. Any advice?

Michael Seifert
  • 15,208
  • 31
  • 68
Rama
  • 41
  • 1
  • 3

1 Answers1

6

You seem unfamiliar with Mathematica syntax.

gr[x_] := Piecewise[{{x, x > 1}, {0, x <= 0}}];

Plot[gr[x], {x, -5, 5}]

Note too that your function is not defined for $0 < x \leq 1$. Is that really what you want?

It is also good programming style to order the elements in a Piecewise from low to high (left-to-right on the number line), i.e.,

Piecewise[{{0, x <= 0}, {x, x > 1}}]
David G. Stork
  • 41,180
  • 3
  • 34
  • 96
  • 4
    I agree with you suggestions but think it is worth pointing out that Piecewise short circuits. So sometimes it is beneficial to sort the arguments such that the most common cases come first. – Andy Ross Jul 07 '15 at 00:22
  • 1
    Also, to fully comply with the "number line" tip: one would want to express inequalities in terms of < or <=; so, 1 < x. – J. M.'s missing motivation Jul 07 '15 at 00:29