This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

taylor

Syntax

taylor(f,var)
taylor(f,var,a)
taylor(___,Name,Value)

Description

example

taylor(f,var) approximates f with the Taylor series expansion of f up to the fifth order at the point var = 0. If you do not specify var, then taylor uses the default variable determined by symvar(f,1).

example

taylor(f,var,a) approximates f with the Taylor series expansion of f at the point var = a.

example

taylor(___,Name,Value) uses additional options specified by one or more Name,Value pair arguments. You can specify Name,Value after the input arguments in any of the previous syntaxes.

Examples

Find Maclaurin Series of Univariate Expressions

Find the Maclaurin series expansions of these functions.

syms x
taylor(exp(x))
taylor(sin(x))
taylor(cos(x))
ans =
x^5/120 + x^4/24 + x^3/6 + x^2/2 + x + 1
 
ans =
x^5/120 - x^3/6 + x
 
ans =
x^4/24 - x^2/2 + 1

Specify Expansion Point

Find the Taylor series expansions at x = 1 for these functions. The default expansion point is 0. To specify a different expansion point, use ExpansionPoint:

syms x
taylor(log(x), x, 'ExpansionPoint', 1)
ans =
x - (x - 1)^2/2 + (x - 1)^3/3 - (x - 1)^4/4 + (x - 1)^5/5 - 1

Alternatively, specify the expansion point as the third argument of taylor:

taylor(acot(x), x, 1)
ans =
pi/4 - x/2 + (x - 1)^2/4 - (x - 1)^3/12 + (x - 1)^5/40 + 1/2

Specify Truncation Order

Find the Maclaurin series expansion for f = sin(x)/x. The default truncation order is 6. Taylor series approximation of this expression does not have a fifth-degree term, so taylor approximates this expression with the fourth-degree polynomial:

syms x
f = sin(x)/x;
t6 = taylor(f, x)
t6 =
x^4/120 - x^2/6 + 1

Use Order to control the truncation order. For example, approximate the same expression up to the orders 8 and 10:

t8 = taylor(f, x, 'Order', 8)
t10 = taylor(f, x, 'Order', 10)
t8 =
- x^6/5040 + x^4/120 - x^2/6 + 1
 
t10 =
x^8/362880 - x^6/5040 + x^4/120 - x^2/6 + 1

Plot the original expression f and its approximations t6, t8, and t10. Note how the accuracy of the approximation depends on the truncation order. Prior to R2016a, use ezplot instead of fplot.

fplot([t6 t8 t10 f])
xlim([-4 4])
grid on

legend('approximation of sin(x)/x up to O(x^6)',...
       'approximation of sin(x)/x up to O(x^8)',...
       'approximation of sin(x)/x up to O(x^{10})',...
       'sin(x)/x','Location','Best')
title('Taylor Series Expansion')

Specify Order Mode: Relative or Absolute

Find the Taylor series expansion of this expression. By default, taylor uses an absolute order, which is the truncation order of the computed series.

taylor(1/(exp(x)) - exp(x) + 2*x, x, 'Order', 5)
ans =
-x^3/3

Fnd the Taylor series expansion with a relative truncation order by using OrderMode. For some expressions, a relative truncation order provides more accurate approximations.

taylor(1/(exp(x)) - exp(x) + 2*x, x, 'Order', 5, 'OrderMode', 'relative')
ans =
- x^7/2520 - x^5/60 - x^3/3

Find Maclaurin Series of Multivariate Expressions

Find the Maclaurin series expansion of this multivariate expression. If you do not specify the vector of variables, taylor treats f as a function of one independent variable.

syms x y z
f = sin(x) + cos(y) + exp(z);
taylor(f)
ans =
x^5/120 - x^3/6 + x + cos(y) + exp(z)

Find the multivariate Maclaurin expansion by specifying the vector of variables.

syms x y z
f = sin(x) + cos(y) + exp(z);
taylor(f, [x, y, z])
ans =
x^5/120 - x^3/6 + x + y^4/24 - y^2/2 + z^5/120 + z^4/24 + z^3/6 + z^2/2 + z + 2

Specify Expansion Point for Multivariate Expression

Find the multivariate Taylor expansion by specifying both the vector of variables and the vector of values defining the expansion point:

syms x y
f = y*exp(x - 1) - x*log(y);
taylor(f, [x, y], [1, 1], 'Order', 3)
ans =
x + (x - 1)^2/2 + (y - 1)^2/2

If you specify the expansion point as a scalar a, taylor transforms that scalar into a vector of the same length as the vector of variables. All elements of the expansion vector equal a:

taylor(f, [x, y], 1, 'Order', 3)
ans =
x + (x - 1)^2/2 + (y - 1)^2/2

Input Arguments

collapse all

Input to approximate, specified as a symbolic expression or function. It also can be a vector, matrix, or multidimensional array of symbolic expressions or functions.

Expansion variable, specified as a symbolic variable. If you do not specify var, then taylor uses the default variable determined by symvar(f,1).

Expansion point, specified as a number, or a symbolic number, variable, function, or expression. The expansion point cannot depend on the expansion variable. You also can specify the expansion point as a Name,Value pair argument. If you specify the expansion point both ways, then the Name,Value pair argument takes precedence.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: taylor(log(x),x,'ExpansionPoint',1,'Order',9)

Expansion point, specified as a number, or a symbolic number, variable, function, or expression. The expansion point cannot depend on the expansion variable. You can also specify the expansion point using the input argument a. If you specify the expansion point both ways, then the Name,Value pair argument takes precedence.

Truncation order of Taylor series expansion, specified as a positive integer or a symbolic positive integer. taylor computes the Taylor series approximation with the order n - 1. The truncation order n is the exponent in the O-term: O(varn).

Order mode indicator, specified as 'absolute' or 'relative'. This indicator specifies whether you want to use absolute or relative order when computing the Taylor polynomial approximation.

Absolute order is the truncation order of the computed series. Relative order n means that the exponents of var in the computed series range from the leading order m to the highest exponent m + n - 1. Here m + n is the exponent of var in the O-term: O(varm + n).

More About

collapse all

Taylor Series Expansion

Taylor series expansion represents an analytic function f(x) as an infinite sum of terms around the expansion point x = a:

f(x)=f(a)+f(a)1!(xa)+f(a)2!(xa)2+=m=0f(m)(a)m!(xa)m

Taylor series expansion requires a function to have derivatives up to an infinite order around the expansion point.

Maclaurin Series Expansion

Taylor series expansion around x = 0 is called Maclaurin series expansion:

f(x)=f(0)+f(0)1!x+f(0)2!x2+=m=0f(m)(0)m!xm

Tips

  • If you use both the third argument a and ExpansionPoint to specify the expansion point, the value specified via ExpansionPoint prevails.

  • If var is a vector, then the expansion point a must be a scalar or a vector of the same length as var. If var is a vector and a is a scalar, then a is expanded into a vector of the same length as var with all elements equal to a.

  • If the expansion point is infinity or negative infinity, then taylor computes the Laurent series expansion, which is a power series in 1/var.

See Also

| |

Introduced before R2006a