# Why is Plot within Manipulate not evaluating here?

I'm trying to get Plot within my Manipulate to evaluate, but I keep getting error messages:

F[x_]:= Cos[x]

Manipulate[
Plot[
Sum[
( ( D[ F[x], {x, k} ] /. x -> (π/6) )/k! ) * (x - (π/6) )^k ,
{k, 1, terms}
],
{x, -3 π, 3 π}
],
{terms, 1, 100, 1}
]


It's supposed to be a taylor series that I can manipulate. Help is appreciated!

Edit: I'm very new to Mathematica, so I would appreciate, if you explained everything in a very simplified manner!

• Try giving the variable with respect to which you're differentiating a different name than the plotting variable. E.g., Manipulate[ Plot[Sum[((D[F[xx], {xx, k}] /. xx -> (\[Pi]/6))/k!)*(x - (\[Pi]/6))^ k, {k, 1, terms}], {x, -3 \[Pi], 3 \[Pi]}], {terms, 1, 100, 1}] – jjc385 Apr 13 '17 at 3:25
• Or, calculate the function before it is supplied to Plot, e.g. With[{fcn = Sum[((D[F[x], {x, k}] /. x -> (\[Pi]/6))/k!)*(x - (\[Pi]/6))^k, {k,1, terms}]}, Plot[fcn, {x, -3 \[Pi], 3 \[Pi]}] ]. – rcollyer Apr 13 '17 at 3:26
• 1. You forgot the constant term. 2. Add Evaluate[]: Manipulate[Plot[Evaluate @ Sum[(* stuff *)], (* stuff *)], (* stuff *)] – J. M. will be back soon Apr 13 '17 at 3:26
• Possible duplicate: mathematica.stackexchange.com/questions/1301/… – Michael E2 Apr 13 '17 at 15:28

Correction

As pointed out by J.M. needs k=0 term to be correct: You can define the sum as function (and change differential variable),e.g.:

sum[x_, n_] :=
Sum[((D[F[u], {u, k}] /. u -> (\[Pi]/6))/k!)*(x - (\[Pi]/6))^k, {k,
0, n}]
Manipulate[Plot[sum[x, n], {x, -3 Pi, 3 Pi}], {n, Range[0,100]}]


This image shows manipulate works for original answer (without constant):

• Thank you so so much this was so helpful. Also, just wondering, why wasn't mine working? – Mmnoob Apr 13 '17 at 3:36
• @Mmnoob your derivative used the same variable as your function and conflcted. Run the sum outside the Manipulate as you have written and try to evaluate it as your desired x and n. The errors will provide you insight. Good luck:) – ubpdqn Apr 13 '17 at 3:39
• You forgot the constant term, too. Sum[(* stuff *), {k, 0, n}]. – J. M. will be back soon Apr 13 '17 at 3:40
• @J.M. I merely rewrote the OP function changing the variable of differentiation. I did not look at content. I may leave for OP to use as desired but your comment may prompt this revelation. – ubpdqn Apr 13 '17 at 3:41
• @ubpdqn Thank you! Just one more question; if I were to implement a range for my "u" value (instead of /.u -> pi/6 I wanted u to range between -2 and 2) how would I alter my function? Much appreciated :) – Mmnoob Apr 13 '17 at 3:44