MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
Taylor series expansions serve for approximating an arbitrary
expression by a polynomial expression around some value of a variable.
Taylor series expansions approximate expressions for which the derivatives
up to infinite order exist around a particular value x0 of
To compute Taylor series expansion, use the
taylor command. For example, approximate
x = 0:
exact := sin(x)/x: approx := taylor(sin(x)/x, x)
Plot the exact expression and its taylor series expansion in
the same coordinate system. The taylor series expansion approximates
the expression near
x = 0, but visibly deviates
sin(x)/x for larger
plot( plot::Function2d(exact, x = -PI..PI, Legend = "sin(x)/x", Color = RGB::Red), plot::Function2d(approx, x = -PI..PI, Legend = "approximation of sin(x)/x") )
Accuracy of an approximation depends on the proximity to the expansion point and on the number of terms used in the series expansion. See how to specify the number of terms in Controlling the Number of Terms in Series Expansions.
Taylor series expansions around
x = 0 are
also called Maclaurin series expansions. Approximate the expressions
by Maclaurin series:
taylor(exp(x), x); taylor(sin(x), x); taylor(cos(x)/(1 - x), x)
The Maclaurin series expansion does not exist for the following expression. MuPAD® throws an error:
Error: Cannot compute a Taylor expansion of 'arccot(x)'. Try 'series' for a more general expansion. [taylor]
You can represent the following expression by a Taylor series
x = 1. To compute the series expansion around
a nonzero value of a variable, specify the value. For example, compute
the Taylor series expansions around
x = 1 for the
taylor(ln(x), x = 1); taylor(arccot(x), x = 1)
s := taylor(sin(x)/exp(x), x); expr(s)