0
$\begingroup$

Currently, I am trying to plot (using Mathematica) the following function:

$$f(t) = \begin{cases} 0, & 0<t<1 \\ 1, & 1<t<2 \end{cases} $$

And, to try to plot this, I did some readings on this StackExchange regarding "Conditions". I did give it a try and for some reason, it isn't working.

Below is my code:

f[t_1 /; 0 < t < 1] := 0

f[t_2 /; 1 < t < 2] := 1

Plot[{t_1, t_2}, {t, -10, 10}]

Any help would be greatly appreciated. Thank you very much!

$\endgroup$
1
  • 2
    $\begingroup$ Why not use Piecewise[]? Plot[Piecewise[{{0, 0 < t < 1}, {1, 1 < t < 2}},Indeterminate], {t, -10, 10}, Axes -> None, Frame -> True] $\endgroup$ Commented Apr 17, 2020 at 15:15

1 Answer 1

1
$\begingroup$

Try

f[t_] := 0 /; 0 < t < 1

see also Step and PieceWise in the documentation.

$\endgroup$
1
  • $\begingroup$ Also f[t_] /; 0 < t < 1 := 0. I think it is the same. $\endgroup$ Commented Apr 17, 2020 at 15:21

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.