# Normal[Series[ ]] does not give a normal expression

Let us say I want to show how the Taylor's series for Sin behaves:

In:= Plot[Normal[Series[Sin[x], {x, 0, 3}]], {x, -π, π}]

During evaluation of In:= General::ivar: -3.14146 is not a valid variable. >>
During evaluation of In:= General::ivar: -3.14146 is not a valid variable. >>
During evaluation of In:= General::ivar: -3.14146 is not a valid variable. >>
During evaluation of In:= General::stop: Further output of General::ivar will be suppressed during this calculation. >>


However, if I just evaluate

In:= Normal[Series[Sin[x], {x, 0, 3}]]

Out= x - x^3/6

In:= Plot[x - x^3/6, {x, -π, π}]

Out= It works fine. What is going on? I am doing this because I want to insert the plot in a Manipulate and then see how the functions behave with more terms of the series.

Update:

Using the answer, I can do

Plot[Evaluate@Normal[Series[Sin[x], {x, 0, 3}]], {x, -π, π}]


However, if I try to compare as in

Plot[{Sin[x], Evaluate@Normal[Series[Sin[x], {x, 0, 3}]]}, {x, -π, π}]


it doesn't work while the explicit Plot[{Sin[x], x - x^3/6}, {x, -π, π}] does.

As kguler shows this is an evaluation order problem.

I recommend a different form however:

Plot[
{Sin[x], Normal[Series[Sin[x], {x, 0, 3}]]},
{x, -π, π},
Evaluated -> True
]


For Plot the undocumented option Evaluated is superior because the plotting variable (x) is still correctly localized, therefore this method works even if you set a global value e.g. x = 1 before plotting.

You asked why this doesn't work:

Plot[{Sin[x], Evaluate@Normal[Series[Sin[x], {x, 0, 3}]]}, {x, -π, π}]


This fails because as the Evaluate documentation under Possible Issues states:

Evaluate works only on the first level, directly inside a held function:

Hold[f[Evaluate[1 + 2]]]

Out= Hold[f[Evaluate[1 + 2]]]

• I think the Evaluated option deserves a short entry in our new blog – Dr. belisarius Jun 28 '12 at 11:55
• Too bad Evaluated option doesn't exist for e.g. LogPlot or ListPlot, so one is forced to wrap the argument in Evaluate[] call. – Ruslan Feb 21 '15 at 8:32

Try

 Plot[Evaluate@Normal[Series[Sin[x], {x, 0, 3}]], {x, -π, π}]


or

 Plot[#, {x, -π, π}] &@Normal[Series[Sin[x], {x, 0, 3}]]


or

 Plot[Normal[Series[Sin[y], {y, 0, 5}]] /. y -> x, {x, -Pi, Pi}]


to force evaluation in the appropriate order.

EDIT:

Plot[Evaluate@{Sin[x], Normal[Series[Sin[x], {x, 0, 3}]]}, {x, -Pi, Pi}]
Plot[{Sin[x], Normal[Series[Sin[x], {x, 0, 3}]]}, {x, -Pi, Pi}, Evaluated->True]
Plot[{Sin[x], #}, {x, -Pi, Pi}] &@Normal[Series[Sin[x], {x, 0, 3}]]
Plot[{Sin[x], Normal[Series[Sin[y], {y, 0, 3}]] /. y -> x}, {x, -Pi,  Pi}]


all give EDIT 2: The error message

 General::ivar: "-3.14146 is not a valid variable."


suggests why Plot[Normal[Series[Sin[x], {x, 0, 5}]], {x, -Pi, Pi}] does not work. Namely, as Plot plugs numerical values x0 from the range (-Pi,Pi) in its first argument, the expression Series[Sin[x0], {x0, 0, 5}]] becomes an invalid expression.

EDIT 3: The option setting Evaluated->True in Mr.Wizard is most straightforward approach. The default setting for that option

 Options[Plot,Evaluated]
(* ==> Automatic *)


By making the default setting for this option True using

SetOptions[Plot, Evaluated -> True];


you can use Plot[...] as usual.

An example:

 s = DSolve[y'[x] == 1/(1 + y[x]), y, x];
Plot[ y[x] /. s /. C -> Range[0, 5], {x, -5, 5}] • And why is Evaluate required? – rcollyer Jun 28 '12 at 4:41
• Plot[Evaluate@Normal[Series[Sin[x], {x, 0, 3}]], {x, -[Pi], [Pi]}] but if I try to do both as Plot[{Sin[x], Evaluate@Normal[Series[Sin[x], {x, 0, 3}]]}, {x, -[Pi], [Pi]}], it doesn't work while Plot[{Sin[x], x - x^3/6}, {x, -[Pi], [Pi]}] does. – highBandWidth Jun 28 '12 at 4:43
• Do I need to edit my answer to say different form which he did not originally show but has now edited his question to include? :^) – Mr.Wizard Jun 28 '12 at 7:43
• @rcollyer, good question ... but I am afraid because of my limited understanding Mma evaluation sequence I can only guess that it has to do with the fact Plot has HoldAll attribute :) Perhaps comments and answers on SE question may provide more concrete clues. – kglr Jun 28 '12 at 8:30
• @Mr.Wizard, I was trying to make sense of your comment for the last 15 minutes ... which seemed puzzling as your answer did not show on my screen despite several edits and screen refreshes that I made during the last several hours. I will delete the part in my post that uses the Evaluated option. – kglr Jun 28 '12 at 8:51