1
$\begingroup$

I would like to plot the Taylor polynomials for several functions. Specifically:

Exp[Sin[x]]
( x^2 + Exp[ x ] )^( -1 )

and

Exp[ -4 x^2 + 5 x]

I have their Taylor series as:

taylorFunction1[x_, n_] := Normal[Series[f1[x], { x, 0, n} ] ]
taylorFunction2[x_, n_] := Normal[Series[f2[x], {x,  0, n} ] ]
taylorFunction3[x_, n_] := Normal[Series[f3[x], {x,  0, n} ] ]

I would like to plot the functions of x and their Taylor series of degree n = 10 and compare each, specifically over the interval [-1/2, 1/2]. However, for some reason, whenever I use the "Plot[]" command, Mathematica just returns an empty graph. I come from a C programming background, but I am rather unfamiliar with Mathematica. Can anyone help me out and let me know what's going on?

Thanks!

$\endgroup$
2
  • $\begingroup$ It's because (probably -- guessing without Plot code) in Plot, the symbol x is given a numeric value whereas Series would fail if x is not a symbol. $\endgroup$
    – Michael E2
    Nov 26, 2017 at 1:14
  • $\begingroup$ Hmm... So do you think changing the variable for x in the function definitions would do the trick? $\endgroup$
    – swandog
    Nov 26, 2017 at 1:16

1 Answer 1

2
$\begingroup$

Here's one way:

Plot[
 Evaluate@Normal@Series[{Exp[Sin[x]], (x^2 + Exp[x])^(-1), Exp[-4 x^2 + 5 x]}, {x, 0, 5}],
 {x, -1/2, 1/2}]

Mathematica graphics

$\endgroup$
4
  • $\begingroup$ Hey Michael, thanks for the response. I see... So is Mathematica actually evaluating the functions, and then plotting every value with x = [-1/2, 1/2]? $\endgroup$
    – swandog
    Nov 26, 2017 at 1:20
  • $\begingroup$ @AlexanderSwanson Yes, the trick is to evaluate Series before assigning values to x. $\endgroup$
    – Michael E2
    Nov 26, 2017 at 1:24
  • $\begingroup$ I see. I'm assuming Evaluate@... does that for us. Thanks a lot, Michael. $\endgroup$
    – swandog
    Nov 26, 2017 at 1:29
  • $\begingroup$ @AlexanderSwanson Right, Plot evaluates its argument in a non-standard way, which Evaluate overrides. $\endgroup$
    – Michael E2
    Nov 26, 2017 at 1:44

Your Answer

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

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