1
$\begingroup$

I wrote a code which plots a Maclaurin expansion of cos(x) in various degrees.

f[x_] := Cos[x]
Animate[
  Plot[Evaluate @ Normal[Series[f[x], {x, 0, s}]],{x, -10 Pi, 10 Pi},
    PlotRange -> {-1, 1}], 
  {s, 0, 80, 2}]

This code works well. Next, I just added the original function to Plot, but it does not work.

f[x_] := Cos[x]
Animate[
  Plot[{Evaluate @ Normal[Series[f[x], {x, 0, s}]], f[x]}, {x, -10 Pi, 10 Pi},
    PlotRange -> {-1, 1}], 
  {s, 0, 80, 2}]

I found that just one function in the List style is also not work correctly.

Plot[{Evaluate @ Normal[Series[f[x], {x, 0, 20}]]}, {x, -10 Pi, 10 Pi},
  PlotRange -> {-1, 1}]

What's wrong with what I am doing?

$\endgroup$
3
  • $\begingroup$ Works in 10.0.0,win 7. $\endgroup$ – Apple Aug 9 '14 at 9:36
  • $\begingroup$ Thanks all for quick reply! I solved the problem! I note that this problem was under V8. $\endgroup$ – user3288408 Aug 9 '14 at 10:41
  • $\begingroup$ m_goldberg And thank you again for correcting my poor English! $\endgroup$ – user3288408 Aug 9 '14 at 10:52
3
$\begingroup$

In V9 (and earlier I presume), Evaluate has to be the head of the argument for which pre-evaluation is wanted. In your example List is the head. See the 2 nd point under Details inEvaluate.

You can fix your code by moving Evaluate so that it is the head of the first argument to Plot

Plot[Evaluate@{Normal[Series[f[x], {x, 0, 20}]], f[x]}, {x, -10 Pi, 10 Pi},
  PlotStyle -> {Automatic, Dotted},
  PlotRange -> {-1, 1}]

plot

In V10, Plot seems to be doing evaluation differently and your example works as is.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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