Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

enter image description here

λ[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}]
share|improve this question

closed as off-topic by m_goldberg, RunnyKine, Teake Nutma, ybeltukov, Yves Klett Sep 4 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.

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

3 Answers 3

up vote 2 down vote accepted

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]}] 

plot2D

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

plot3D

share|improve this answer
    
Do I also have to do this if I numerically integrate them? –  Minamoto Sep 4 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? –  Minamoto Sep 4 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 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]}]

enter image description here

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

enter image description here

share|improve this answer

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}]

enter image description here

share|improve this answer

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