How and when to use Evaluate?

A month ago, I used Mathematica to solve my experiment of the Test Technology of Mechanics Engineering. The exeriment is mainly about the Fourier Transform and verify the validity of the theory of Fourier. My code is below:

originwave[t_] :=
If[-5 <= t <= 5, t, If[t > 0, originwave[t - 10], originwave[t + 10]]];
(*the definition of SawtoothWave function*)

four periodic originwave

Column[
{Plot[originwave[t], {t, -20, 20}, PlotRange -> {-5, 5},
AspectRatio -> 1, ImageSize -> 300, AxesStyle -> Arrowheads[0.03],
AxesLabel -> {"t", "four periodic originwave"}
]},
Center] The seven order Fourier series expansion

Column[
{Plot[Evaluate[FourierTrigSeries[originwave[t], t, 7]], {t, -20, 20},
PlotRange -> {-5, 5}, AspectRatio -> 1, ImageSize -> 300,
AxesLabel -> {"t", "The seven order Fourier series expansion"}]},
Center] Furthermore,I encounter a problem about Taylor Series that we can use the approximate value of Maclaurin Series to replace a function. I can see the degree of closeness between them by changing the variable n. That's my trial:

Manipulate[
Show[
Plot[E^x, {x, 0, 5}, PlotStyle -> Pink],
Plot[Evaluate@Normal@Series[E^x, {x, 0, n}], {x, 0, 5},
PlotRange -> {0, 150}]],
{{n, 6}, 0, 10, 1, Appearance -> "Labeled"}] Lastly ,the problem of plotting 2-D graph of |x|+|2x+y|=1, below is the solution:

Plot[y /. Solve[Abs@x + Abs@(x + y) == 1, y, Reals] //
Evaluate, {x, -2, 2}, AspectRatio -> Automatic] Summary and my confusion:

In three tasks, I am alway using the Evaluate command. Firstly,I know this command and I will remember it when the MMA cannot give the result that I want. However, it is confusing to me that I don't know when to use it or not use it. Can someone help me?

• There's actually a built in SawtoothWave function in Mathematica – RunnyKine Oct 19 '13 at 10:12
• You should use it in arguments that are otherwise held and you don't want that to happen – Rojo Oct 19 '13 at 12:37
• And ... (continuing @Rojo's statement) ... Plot[] is HoldAll – Dr. belisarius Oct 19 '13 at 13:42
• – Jacob Akkerboom Oct 19 '13 at 18:08
• (Slightly less) related: How are parameters evaluated for a Plot in Manipulate – Jacob Akkerboom Oct 20 '13 at 11:22

[Too long for comment]

Here's a simple example of what is going on:

f is a slow to evaluate function:

f[x_] := (Pause[0.01]; x^2)
AbsoluteTiming[Plot[f[x], {x, 0, 1}];]            (* 1.6s *)
AbsoluteTiming[Plot[Evaluate[f[x]], {x, 0, 1}];]  (* 0.012s *)

The speed comes from calculating the symbolic result and substituting values into that, since as far as Plot is concerned the second version is the same as Plot[x^2, ...]. In the first case it will call f[x] for each point. Without to the HoldAll attribute Plot would not even have been aware of f[x]

In your case with FourierTrigSeries[originwave[t], t, 7] without Evaluate Plot would replace all occurances of t with numerical values doing things like:

FourierTrigSeries[originwave[0.3], 0.3, 7]
(* FourierTrigSeries[0.3, 0.3, 7] *)

Leading to expressions like above that don't make any sense. When you wrap it in Evaluate Plot will instead see the evaluated form of the original expression:

FourierTrigSeries[originwave[t], t, 7]
(* 2 Sin[t] - Sin[2 t] + 2/3 Sin[3 t] - 1/2 Sin[4 t] +
2/5 Sin[5 t] - 1/3 Sin[6 t] + 2/7 Sin[7 t] *)

It is all about the attributes of the function you are considering. In particular it is about Hold-Attributes. In your case the function Plot has attribute HoldAll. You can see this by using the function Attributes:

Attributes[Plot]