taylor -- compute a Taylor series
expansion
Introductiontaylor(f, x = x0) computes the first terms
of the Taylor series of f with respect to the variable
x around the point x0.
Call(s)taylor(f, x < = x0> <, order>)
Parametersf |
- | an arithmetical expression
representing a function in x |
x |
- | an identifier |
x0 |
- | the expansion point: an arithmetical expression; if not specified, the default expansion point 0 is used. |
order |
- | the number of terms to be computed: a nonnegative
integer; the default order is given by the environment variable
ORDER (default value
6). |
Returnsan object of domain type Series::Puiseux or a symbolic
expression of type "taylor".
Side
EffectsThe function is sensitive to the environment variable ORDER, which determines the default
number of terms in series computations.
f
Related
Functionsasympt, diff, limit, O, series, Series::Puiseux, Type::Series
Detailstaylor tries to compute the Taylor series of
f around x = x0. Three cases can occur:
taylor is able to compute the corresponding Taylor
series. In this case, the result is a series expansion of domain type
Series::Puiseux. Use
expr to convert it to an
arithmetical expression of domain type DOM_EXPR. Cf. example 1.taylor is able to decide that the corresponding Taylor
series does not exist. In this case, an error is raised. Cf. example 2.taylor is not able to determine whether the
corresponding Taylor series exists or not. Internally, the function
series is called; it
returns a symbolical call. In this case, also taylor
returns a symbolic expression of type "taylor". Cf.
example 3.taylor is
valid in some neighborhood of the expansion point in the complex
plane.x0 is infinity or -infinity, a ``directional'' series expansion
valid along the real axis is computed.
Such an expansion is computed as follows: The series variable
x in f is replaced by x = 1/u.
Then a directional series expansion at u = 0+ is computed.
Finally, u = 1/x is substituted in the result.
Mathematically, the result of an expansion around
+-infinity
is a power series in 1/x. Cf. example 4.
order if specified. Otherwise, the value of the
environment variable ORDER is used. You can change the
default value 6 by assigning a new value to ORDER.
The number of terms is counted from the lowest degree term on, i.e.,
``order'' has to be regarded as a ``relative truncation
order''.
Note, however, that the actual number of terms in
the resulting series expansion may differ from the requested number of
terms (cf. example 5). See series for details.
taylor uses the more general series function series to compute the Taylor
expansion. See the corresponding help page for series for
details about the parameters and the data structure of a Taylor series
expansion.
Example
1We compute a Taylor series around the default point 0:
>> s := taylor(exp(x^2), x)
4
2 x 6
1 + x + -- + O(x )
2
The result of taylor is of the following
domain type:
>> domtype(s)
Series::Puiseux
If we apply the function expr to a series, we get an
arithmetical expression without the order term:
>> expr(s); domtype(%)
4
2 x
x + -- + 1
2
DOM_EXPR
>> delete s:
Example
2A Taylor series expansion of f(x) = 1/(x^2-1)
around x = 1 does not exist. Therefore, taylor
responds with an error message:
>> taylor(1/(x^2 - 1), x = 1)
Error: does not have a Taylor series expansion, try 'series' [\
taylor]
Following the advice given in this error message, we try
series to compute a
more general series expansion. A Laurent expansion does exist:
>> series(1/(x^2 - 1), x = 1)
2 3
1 / x \ (x - 1) (x - 1)
--------- - 1/4 + | - - 1/8 | - -------- + -------- +
2 (x - 1) \ 8 / 16 32
4
O((x - 1) )
Example
3If a Taylor series expansion cannot be computed, then the function call with evaluated arguments is returned symbolically together with a warning:
>> taylor(1/exp(x^a), x = 0)
Warning: could not compute Taylor series expansion; try 'serie\
s' with option 'Left', 'Right', or 'Real' for a more general e\
xpansion [taylor]
/ 1 \
taylor| -------, x = 0 |
| a |
\ exp(x ) /
In this example, also series returns a symbolic function
call. Even if you try one of the proposed options, series
is not able to compute a series expansion.
Here is another example where no Taylor expansion can be computed.
However, series with an
optional argument yields a more general type of expansion in this
case:
>> taylor(psi(1/x), x = 0)
Warning: could not compute Taylor series expansion; try 'serie\
s' with option 'Left', 'Right', or 'Real' for a more general e\
xpansion [taylor]
/ / 1 \ \
taylor| psi| - |, x = 0 |
\ \ x / /
>> series(psi(1/x), x = 0, Right)
2 4
/ 1 \ x x x 5
ln| - | - - - -- + --- + O(x )
\ x / 2 12 120
Example
4This is an example of a ``directional'' Taylor expansion
along the real axis around infinity:
>> taylor(exp(1/x), x = infinity)
1 1 1 1 1 / 1 \
1 + - + ---- + ---- + ----- + ------ + O| -- |
x 2 3 4 5 | 6 |
2 x 6 x 24 x 120 x \ x /
Example
5Here is an example where the actual number of computed terms differs from the requested number:
>> taylor((sin(x^4) - tan(x^4)) / x^10, x, 15)
2
x 5
- -- + O(x )
2
taylor returns an expression of type
"taylor" if a Taylor series could not be computed (this
does not necessarily mean that a Taylor expansion does not exist).