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?
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?
There are couple of problems with your code.
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.
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?
$\endgroup$
f[x_] := ...
notf[x] := ...
. Please see Defining functions. $\endgroup$