taylor

The taylor command is used to compute Taylor polynomials of functions. The syntax of taylor is almost Maple's usual

taylor(what,how);

syntax, except that the "how" part is a little more complicated than usual. "What" in this case refers to "compute the Taylor polynomial of what function?", and "how" to "centered at what point and to what degree" -- since "how" is a two-part question, there are two pieces required in the answer.  For example, to compute the Taylor polynomial of degree 4 of the function
exp(sin(x)) centered at x=0, we would enter:

>   restart:

>   taylor(exp(sin(x)),x=0,5);

series(1+1*x+1/2*x^2-1/8*x^4+O(x^5),x,5)

The order of the arguments is crucial -- first is the expression whose Taylor polynomial is to be found, second is the variable and value around which the expansion is to be taken, and third is one plus the degree.   The third argument to taylor actually specifies the degree of the first term to be omitted from the expansion (or the degree of the error term).

A remark about the output is in order -- note the
O(x^5) at the end of the output. This indicates that the output is a Taylor expansion with error which behaves like a constant times x^5 for small values of x.  While this is useful information, often we compute Taylor polynomials with the intention of using them as polynomials for some other purpose (i.e., substituing values for  the variable, integrating, etc..). Before almost any such manipulations can be done, the output must be converted into a polynomial. The command which accomplishes this is convert -- the expression convert(--- , polynom); changes the expression behind the "---" into a polynomial (i.e., it drops the O(x^n) part). For example:

>   t:=taylor(exp(sin(x)),x=0,5);

t := series(1+1*x+1/2*x^2-1/8*x^4+O(x^5),x,5)

>   u:=convert(t,polynom);

u := 1+x+1/2*x^2-1/8*x^4

The only difference between t and u is the "O" term -- but, for instance, we cannot substitute a value of x into t:

>   subs(x=3,t);

Error, invalid substitution in series

while we can do this to u:

>   subs(x=3,u);

-13/8

The moral is that taylor is almost always used in tandem with convert.

Other parameters and variables are permitted in the
taylor command. For example, you can calculate:

>   taylor(1/(x-a),x=b,5);

series(1/(b-a)+1/((-b+a)*(b-a))*(x-b)+1/((-b+a)^2*(b-a))*(x-b)^2+1/((-b+a)^3*(b-a))*(x-b)^3+1/((-b+a)^4*(b-a))*(x-b)^4+O((x-b)^5),x=-(-b),5)
series(1/(b-a)+1/((-b+a)*(b-a))*(x-b)+1/((-b+a)^2*(b-a))*(x-b)^2+1/((-b+a)^3*(b-a))*(x-b)^3+1/((-b+a)^4*(b-a))*(x-b)^4+O((x-b)^5),x=-(-b),5)


The third argument, which specifies the degree of the approximation, must always be a positive whole number, however:

>   taylor(exp(x),x=4,n);

Error, wrong number (or type) of parameters in function taylor


Maple's objection here is to the "n" --

>   taylor(exp(x),x=4,2.3);

Error, wrong number (or type) of parameters in function taylor

Again, the number of terms must be a positive whole number.

Taylor expansions of functions may only be performed about points where the functions are continuous and differentiable (a sufficient number of times). For example, since sin(0)=0, it is not valid to ask for the Taylor polynomial of 1/sin(x) expanded around x=0:

>   taylor(1/sin(x),x=0,5);

Error, does not have a taylor expansion, try series()


Maple has a more powerful
series command (which can do other kinds of expansions besides Taylor expansions, such as asymptotic expansions and Laurent series) that we will not be using before Math 241.

Variations:

Several variations on the syntax of
taylor are permitted (usually to leave something out). First of all, there is a Maple "system variable" called Order (Maple uses this to limit how hard it works to find limits, etc..) -- you can find out the value of this variable as follows:

>   Order;

6

(this is the usual default value). The value of Order may be changed by assigning another number to it, but this is usually not a good idea. In the taylor command, if the third argument is not specified, Maple will assume that you want the Taylor polynomial with error of degree Order (in this case, 6). For example:

>   taylor(ln(x),x=1);

series(1*(x-1)-1/2*(x-1)^2+1/3*(x-1)^3-1/4*(x-1)^4+1/5*(x-1)^5+O((x-1)^6),x=-(-1),6)


Another variation is to leave out the value around which the expansion is to be made (the variable name must always be present, just as in
diff and int, though). In this case, Maple assumes you want to expand about zero:

>   taylor(exp(a*x),x,3);

series(1+a*x+1/2*a^2*x^2+O(x^3),x,3)


Of course, you can combine the two variations:

>   taylor(sin(x),x);

series(1*x-1/6*x^3+1/120*x^5+O(x^6),x,6)

 
Other than what was indicated above, few things can go wrong using the
taylor command, other than syntax errors -- except possibly that sometimes the variable in the command (the x above) has already been given a value that you forgot about:

>   x:=3;

x := 3

>   taylor(sin(x),x=4,2);

Error, wrong number (or type) of parameters in function taylor

Remark: The taylor command can be used only for single-variable expansions (althouth parameters are permitted, as illustrated above). For Taylor expansions of functions of several variables, there is a command called mtaylor. See Maple's Help menu for information on this command.