# General::ivar 0 is not a valid variable when using Series in Plot

I have been having some trouble graphing a Taylor series approximation (Series).

f[x] := Series[E^(-x/4) Sin[3 * x], {x, 1, 4}]

Plot[f[x], {x, 0, 6}]


General::ivar: 0.00012257142857142857 is not a valid variable.

How can I fix this error?

• Use f[x_] := ... not f[x] := .... Please see Defining functions. – Szabolcs Aug 1 at 5:39
• @Szabolcs and others, I reopened the question because that comment is not an answer. As shown in the last code block in my answer it does not even need to be a part of the answer. I believe voters were influenced by your comment but I won't reopen it again if it gets closed again. – Kuba Aug 1 at 9:14
• Please include the message name to make it easier for others who have the same problem to search for and find this question – Michael E2 Aug 1 at 11:47
• @Kuba Duplicate?: mathematica.stackexchange.com/q/48980/4999 – Michael E2 Aug 1 at 11:49
• – Michael E2 Aug 1 at 11:53

There are couple of problems with your code.

1. It is an image, it would be way nicer not to have to rewrite it.
2. Plotting Series

If you go to ref / Series / Application you will see that Normal is used to plot a Series as otherwise O[x]^n will make Plot confused.

3. Function definition

Functions are defined more or less like that f[x_]:=... but if x is an argument to your function then Series spec {x,1,4} will become invalid as x will be replace with the passed value.

You need to create series before you pass the value. One way to do this is to create series once for all by doing it during definition: = vs :=:

So a 'proper way' to get what you need is:

ClearAll[f];

f[x_] = Normal @ Series[E^(-x/4) Sin[3 x], {x, 1, 4}]

Plot[f[x], {x, 0, 6}]


Coincidentally you original code was close to working, if you know what is going on:

ClearAll[f];
f[x] := Series[E^(-x/4) Sin[3 x], {x, 1, 4}]

Plot[Evaluate@Normal@f[x], {x, 0, 6}]


But this is not a way to go anyway.

• ClearAll[f,x]`? If you are ensuring there are no lingering definitions, then probably address all the symbols involved? – rhermans Aug 2 at 9:23