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

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

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

However, if I just evaluate

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

Out[95]= x - x^3/6

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


enter image description here

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.


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.


2 Answers 2


As kguler shows this is an evaluation order problem.

I recommend a different form however:

  {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[1]= Hold[f[Evaluate[1 + 2]]]
  • 2
    $\begingroup$ I think the Evaluated option deserves a short entry in our new blog $\endgroup$ Commented Jun 28, 2012 at 11:55
  • $\begingroup$ Too bad Evaluated option doesn't exist for e.g. LogPlot or ListPlot, so one is forced to wrap the argument in Evaluate[] call. $\endgroup$
    – Ruslan
    Commented Feb 21, 2015 at 8:32


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


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


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

to force evaluation in the appropriate order.


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

enter image description here

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

 (* ==> 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[1] -> Range[0, 5], {x, -5, 5}]

enter image description here

  • $\begingroup$ And why is Evaluate required? $\endgroup$
    – rcollyer
    Commented Jun 28, 2012 at 4:41
  • $\begingroup$ 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. $\endgroup$ Commented Jun 28, 2012 at 4:43
  • $\begingroup$ 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? :^) $\endgroup$
    – Mr.Wizard
    Commented Jun 28, 2012 at 7:43
  • $\begingroup$ @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. $\endgroup$
    – kglr
    Commented Jun 28, 2012 at 8:30
  • $\begingroup$ @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. $\endgroup$
    – kglr
    Commented Jun 28, 2012 at 8:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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