1
$\begingroup$

Since I am new to Mathematica, I have no idea to define a function directly from the Series. For example, if I define

f1[x_] := Normal[Series[e^x, {x, 0, 5}]]

if I input any value, say 0,

Function[x, Series[e^x, {x, 0, 5}]][0]

it will give me warning that "0 is not a valid variable".

Hence, how can I build a pure function from Serie without any warning?

By the way, are there any recommended books for beginners to study the language in Mathematica? Since I find, reading helps does not really help me learn some new clauses, functions and language structure.

Thanks

$\endgroup$
2

1 Answer 1

2
$\begingroup$

Some managing the order of operations is required here. Normal[Series[E^x, {x, 0, 5}] generates the right form, but the function argument replacement takes place before the series expansion normally, so:

Function[x, Series[E^x, {x, 0, 5}]][0]

Expands to:

Series[E^0, {0, 0, 5}]

Which should be fairly obviously nonsense.

Instead, we can tell Mathematica to evaluate the series during the definition of the function rather than as part of the definition of the function:

f[x_] := Evaluate[Normal[Series[E^x, {x, 0, 5}]]];

Then we can use this f normally, for example by calling f[2] to get 109/15.

Please also note the use of capital E for the constant. All Mathematica built-ins start with capital letters, including E, Pi, and so on.

For information on books, I would recommend starting by looking at the tag on this site.

$\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.