0
$\begingroup$

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!

$\endgroup$
  • 1
    $\begingroup$ 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}] $\endgroup$ – jjc385 Apr 13 '17 at 3:25
  • $\begingroup$ 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]}] ]. $\endgroup$ – rcollyer Apr 13 '17 at 3:26
  • 1
    $\begingroup$ 1. You forgot the constant term. 2. Add Evaluate[]: Manipulate[Plot[Evaluate @ Sum[(* stuff *)], (* stuff *)], (* stuff *)] $\endgroup$ – J. M. will be back soon Apr 13 '17 at 3:26
  • $\begingroup$ Possible duplicate: mathematica.stackexchange.com/questions/1301/… $\endgroup$ – Michael E2 Apr 13 '17 at 15:28
2
$\begingroup$

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): enter image description here

$\endgroup$
  • $\begingroup$ Thank you so so much this was so helpful. Also, just wondering, why wasn't mine working? $\endgroup$ – Mmnoob Apr 13 '17 at 3:36
  • $\begingroup$ @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:) $\endgroup$ – ubpdqn Apr 13 '17 at 3:39
  • $\begingroup$ You forgot the constant term, too. Sum[(* stuff *), {k, 0, n}]. $\endgroup$ – J. M. will be back soon Apr 13 '17 at 3:40
  • $\begingroup$ @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. $\endgroup$ – ubpdqn Apr 13 '17 at 3:41
  • $\begingroup$ @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 :) $\endgroup$ – Mmnoob Apr 13 '17 at 3:44

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.