Suppose I try to run the following code:
f[x_] := Cos[x]
F[X_] := Normal[Series[f[x], {x, X, 5}]]
Plot[Table[F[n], {n, -5, 5, 1}], {x, -Pi, Pi}]
Mathematica will give me a series of errors like:
General::ivar: -3.14146 is not a valid variable.
General::stop: Further output of General::ivar will be suppressed during this calculation.
But I can solve it writing:
f[x_] := Cos[x]
F[X_] := Evaluate@Normal[Series[f[x], {x, X, 5}]]
Plot[Table[F[n], {n, -5, 5, 1}], {x, -Pi, Pi}]
I suspect that what happens in the first case is that Mathematica tries to substitute every $x$ in Normal[Series[f[x], {x, X, 5}]]
by $-\pi$ in which case, this yields: Normal[Series[f[-Pi], {-Pi, X, 5}]]
which is nonsense. But if I try:
f[x_] := Cos[x]
F[X_] := Plot[f[x], {x, 0, 2 Pi}]
Table[F[n], {x, -1, 1, 1}]
This doesn't yield any problems. By running:
Attributes[Plot]
Attributes[Normal]
Attributes[Series]
I get:
{HoldAll, Protected, ReadProtected}
{Protected}
{Protected}
So I suspect that it is the attribute "HoldAll" that is changing the order of computation here. Reading the help files about HoldAll
, it says:
is an attribute that specifies that all arguments to a function are to be maintained in an unevaluated form.
It's not clear to me what this means. Does it means that HoldAll
does what Evaluate
does in the example I provided?
HoldAll
, you should also read the Non-Standard Evaluation tutorial. $\endgroup$