# Why do plot functions fail to plot expressions containing piecewise functions? [closed]

Why do both of the following plots appear empty in Mathematica? I tried evaluating the functions $\chi_+$ and $\chi_-$ at various points and it seems valid, so why does Mathematica not plot them?

λ[t_] := 1 + 2 t;
Subscript[t, final] = 2;
τ[u_] := Subscript[t, final] - u;

SubPlus[χ][t_, u_] := Piecewise[{{λ[t], t < τ[u]}, {λ[τ[u]], t > τ[u]}}];
SubMinus[χ][t_, u_] := Piecewise[{{λ[0], t < u}, {λ[t - u], t > u}}];

Plot[SubPlus[χ][t, .4] - SubMinus[χ][t, .4], {t, 0, Subscript[t, final]}]
Plot3D[SubPlus[χ][t, u] - SubMinus[χ][t, u], {t, 0, Subscript[t, final]}, {u, 0, 1}]

-

## closed as off-topic by m_goldberg, RunnyKine, Teake Nutma, ybeltukov, Yves KlettSep 4 '14 at 8:39

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – m_goldberg, RunnyKine, Teake Nutma, ybeltukov, Yves Klett
If this question can be reworded to fit the rules in the help center, please edit the question.

Just wrap all the functions to be plotted in Evaluate. –  Jens Sep 3 '14 at 23:27

You should understand that all the various plot functions have non-standard evaluation -- that is, they have the attribute HoldAll. Therefore, if you give a plot function an argument that won't get evaluated properly inside the plot function, you must pass in an evaluated form.

Plot[Evaluate[SubPlus[χ][t, .4] - SubMinus[χ][t, .4]], {t, 0, Subscript[t, final]}]


Plot3D[Evaluate[SubPlus[χ][t, u] - SubMinus[χ][t, u]], {t, 0, Subscript[t, final]},
{u, 0, 1}]


-
Do I also have to do this if I numerically integrate them? –  Daniel Sep 4 '14 at 0:12
And is it considered bad practise / why is it bad if I simply put every function into Evaluate[] brackets as Jens suggested? –  Daniel Sep 4 '14 at 0:13
@Minamoto. 1) very likely, but depends on what you get out of numerical integration. 2) I don't think Jens suggested that. I think his advice was specific to your particular expressions. WRI has done a lot over the years to improve the various plot functions internal evaluation of their first arguments, so in many cases wrapping in Evaluate is not needed. –  m_goldberg Sep 4 '14 at 0:22

You used t to mean two different things. Change the plot variable t to something else (e.g., var):

λ[t_] := 1 + 2 t;
Subscript[t, final] = 2;
τ[u_] := Subscript[t, final] - u;

SubPlus[χ][t_, u_] := Piecewise[{{λ[t], t < τ[u]}, {λ[τ[u]], t > τ[u]}}];

SubMinus[χ][t_, u_] := Piecewise[{{λ[0], t < u}, {λ[t - u], t > u}}];

Plot[SubPlus[χ][var, .4] - SubMinus[χ][var, .4], {var, 0, Subscript[t, final]}]


Plot3D[SubPlus[χ][var, u] - SubMinus[χ][var, u], {var, 0, Subscript[t, final]}, {u, 0, 1}]


-

This works for me. The Subscript seems to mess things up.

λ[t_] := 1 + 2 t;
tf = 2;
τ[u_] := tf - u;

SubPlus[χ][t_, u_] :=
Piecewise[{{λ[t], t < τ[u]}, {λ[τ[u]],
t > τ[u]}}];
SubMinus[χ][t_, u_] :=
Piecewise[{{λ[0], t < u}, {λ[t - u], t > u}}];

Plot[SubPlus[χ][t, .4] - SubMinus[χ][t, .4], {t, 0, tf}]
Plot3D[SubPlus[χ][t, u] - SubMinus[χ][t, u], {t, 0, tf}, {u, 0, 1}]


-