0
$\begingroup$

I have a polynomial:

f[x_] := x^3 + 2*x^2 + 4

and I create a function that implements the Taylor expansion:

ft[x_, x0, n] := Normal[Series[f[x], {x, x0, n}]] 

If I implement the expansion, the output is as expected:

ft[x, 5, 2]

(179 + 95 (-5 + x) + 17 (-5 + x)^2)

If I then plot the output, it works as expected:

Plot[179 + 95 (-5 + x) + 17 (-5 + x)^2, {x, -10, 10}]

But if I do it in one step, I obtain an error:

Plot[{f[x], ft[x, 5, 2]}, {x, 0, 10}]

(General::stop: Further output of General::ivar will be suppressed during this calculation.)

  • Why causes this error?
  • How I can solve it keeping the one step approach? I know there are examples such as this one, but they use multiple steps.
$\endgroup$
4
  • 2
    $\begingroup$ Search for “ivar Plot” on this site for answers. Here’s one such Q&A: mathematica.stackexchange.com/q/1301/4999. What happens is that your functions aren’t evaluated until after Plot gives x a numerical value. In effect it’s evaluating Series[f[0.], {0., 5, 2}] etc. $\endgroup$
    – Michael E2
    Oct 9, 2022 at 22:01
  • $\begingroup$ Hi, you can reduce your problem to "why is my plot not working" (removing the Taylor expansion back story). Although I knew the answer to the problem, I was curious how quickly one could find the answer here as it is one of the most popular issues. I typed "plot not working" in the search box and found a question entitled plot not working that should solve this problem. Learning to search for solutions here is a valuable skill to have that will allow you to get solutions to your problems a lot faster. $\endgroup$ Oct 9, 2022 at 22:25
  • $\begingroup$ That said, I am actually curious as to why I actually do not get an error. Maybe something changed in the version that I have 13.1 $\endgroup$ Oct 9, 2022 at 22:26
  • $\begingroup$ For more common issues one can encounter using Mathematica there is this question $\endgroup$ Oct 9, 2022 at 22:28

1 Answer 1

1
$\begingroup$
f[x_] := x^3 + 2*x^2 + 4
ft[x_, x0_, n_] := Normal[Series[f[x], {x, x0, n}]]

ft[x, 5, 2]

179 + 95 (-5 + x) + 17 (-5 + x)^2

Plot[{f[x], Evaluate@ft[x, 5, 2]}, {x, 0, 10}]

enter image description here

$\endgroup$

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.