泰勒展开
1.泰勒定理
若函数
f
(
x
)
f(x)
f(x)在
x
0
x_0
x0处n阶可微,则
f
(
x
)
=
∑
k
=
0
n
f
(
k
)
(
x
)
k
!
(
x
−
x
0
)
k
+
R
n
(
x
)
f(x) = \sum_{k=0}^{n}\frac{f^{(k)}(x)}{k!}(x-x_0)^k+R_n(x)
f(x)=k=0∑nk!f(k)(x)(x−x0)k+Rn(x)
其中,
R
n
(
x
)
R_n(x)
Rn(x)称为
f
(
x
)
f(x)
f(x)的余项,常用的余项公式如下所示:
佩亚诺型余项: R n ( x ) = o ( ( x − x 0 ) n ) R_n(x) = o((x-x_0)^n) Rn(x)=o((x−x0)n)
拉格朗日型余项:
R
n
(
x
)
=
f
(
n
+
1
)
(
ξ
)
(
n
+
1
)
!
(
x
−
x
0
)
(
n
+
1
)
R_n(x)=\frac{f^{(n+1)}(\xi)}{(n+1)!}(x-x_0)^{(n+1)}
Rn(x)=(n+1)!f(n+1)(ξ)(x−x0)(n+1)
其中,
ξ
\xi
ξ是介于x与
x
0
x_0
x0之间的一个数,特别的,当
x
0
=
0
x_0 = 0
x0=0时的带拉格朗日余项的泰勒公式如下:
f
(
x
)
=
f
(
0
)
+
f
′
(
0
)
x
+
f
′
′
(
0
)
2
!
x
2
+
⋯
+
f
(
n
)
(
0
)
n
!
x
n
+
f
(
n
+
1
)
(
ξ
)
(
n
+
1
)
!
x
n
+
1
,
(
0
<
ξ
<
x
)
f(x)=f(0)+f^{\prime}(0) x+\frac{f^{\prime \prime}(0)}{2 !} x^{2}+\cdots+\frac{f^{(n)}(0)}{n !} x^{n}+\frac{f^{(n+1)}(\xi)}{(n+1) !} x^{n+1},(0<\xi<x)
f(x)=f(0)+f′(0)x+2!f′′(0)x2+⋯+n!f(n)(0)xn+(n+1)!f(n+1)(ξ)xn+1,(0<ξ<x)
该方程称为麦克劳林公式。
下面给出几种常用的带拉格朗日余项的泰勒公式展开:
1)
e
x
=
1
+
x
+
x
2
2
!
+
.
.
.
+
x
n
n
!
+
e
(
θ
x
)
(
n
+
1
)
!
x
(
n
+
1
)
e^x=1+x+\frac{x^2}{2!}+...+\frac{x^n}{n!}+\frac{e^{(\theta x)}}{(n+1)!}x^{(n+1)}
ex=1+x+2!x2+...+n!xn+(n+1)!e(θx)x(n+1)
2)
s
i
n
(
x
)
=
x
−
x
3
3
!
+
.
.
.
+
(
−
1
)
(
n
−
1
)
x
(
2
n
−
1
)
(
2
n
−
1
)
!
+
(
−
1
)
n
x
(
2
n
+
1
)
(
2
n
+
1
)
!
sin(x)=x-\frac{x^3}{3!}+...+(-1)^{(n-1)}\frac{x^{(2n-1)}}{(2n-1)!}+(-1)^n\frac{x^{(2n+1)}}{(2n+1)!}
sin(x)=x−3!x3+...+(−1)(n−1)(2n−1)!x(2n−1)+(−1)n(2n+1)!x(2n+1)
3)
c
o
s
(
x
)
=
1
−
x
2
2
!
+
.
.
.
+
(
−
1
)
n
x
(
2
n
)
(
2
n
)
!
+
(
−
1
)
(
n
+
1
)
c
o
s
θ
x
(
2
n
+
2
)
!
x
(
2
n
+
2
)
cos(x)=1-\frac{x^2}{2!}+...+(-1)^n\frac{x^{(2n)}}{(2n)!}+(-1)^{(n+1)}\frac{cos\theta x}{(2n+2)!}x^{(2n+2)}
cos(x)=1−2!x2+...+(−1)n(2n)!x(2n)+(−1)(n+1)(2n+2)!cosθxx(2n+2)
4)
l
n
(
1
+
x
)
=
x
−
x
2
2
+
.
.
.
+
(
−
1
)
(
n
−
1
)
x
n
n
+
(
−
1
)
n
x
(
n
+
1
)
(
n
+
1
)
(
1
+
θ
x
)
(
n
+
1
)
ln(1+x)=x-\frac{x^2}{2}+...+(-1)^{(n-1)}\frac{x^n}{n}+(-1)^n\frac{x^{(n+1)}}{(n+1)(1+\theta x)^{(n+1)}}
ln(1+x)=x−2x2+...+(−1)(n−1)nxn+(−1)n(n+1)(1+θx)(n+1)x(n+1)
5)
(
1
+
x
)
α
=
1
+
α
x
+
α
(
α
−
1
)
2
!
x
2
+
.
.
.
+
α
(
α
−
1
)
.
.
.
(
α
−
n
+
1
)
n
!
x
n
+
α
(
α
−
1
)
.
.
.
(
α
−
n
+
1
)
(
α
−
n
)
(
n
+
1
)
!
(
1
+
θ
x
)
(
α
−
n
−
1
)
x
(
n
+
1
)
(1+x)^\alpha = 1+\alpha x+\frac{\alpha(\alpha-1)}{2!}x^2+...+\frac{\alpha(\alpha-1)...(\alpha-n+1)}{n!}x^n+\frac{\alpha(\alpha-1)...(\alpha-n+1)(\alpha-n)}{(n+1)!}(1+\theta x)^{(\alpha-n-1)}x^{(n+1)}
(1+x)α=1+αx+2!α(α−1)x2+...+n!α(α−1)...(α−n+1)xn+(n+1)!α(α−1)...(α−n+1)(α−n)(1+θx)(α−n−1)x(n+1)
以上就是总结的几个常用的泰勒展开。
2.MATLAB实现方法
从上面的例子可以看出,麦克劳林公式实际上就是将 f ( x ) f(x) f(x)表示为 x n x^n xn的和的形式,而在MATLAB中实现泰勒展开的函数为taylor,其具体的语法格式如下所示:
实例:
(1)求 e x 2 e^{x^2} ex2的7阶麦克劳林近似展开
syms x
f = exp(x^2);
f7 = taylor(f)
f7 =
x^4/2 + x^2 + 1
(2)求 s i n x x \frac{sinx}{x} xsinx的5阶麦克劳林型展开
syms x
f = sin(x)/x;
f5=taylor(f)
f5 =
x^4/120 - x^2/6 + 1
(3)求 f ( x ) = a s i n ( x ) + b c o s ( x ) + c t a n ( x ) f(x)=asin(x)+bcos(x)+ctan(x) f(x)=asin(x)+bcos(x)+ctan(x)的10阶麦克劳林展开
syms x a b c
f = a*sin(x)+b*cos(x)+c*tan(x);
f10 = taylor(f,x,'order',10)
f10 =
(a/362880 + (62*c)/2835)*x^9 + (b*x^8)/40320 + ((17*c)/315 - a/5040)*x^7 - (b*x^6)/720 + (a/120 + (2*c)/15)*x^5 + (b*x^4)/24 + (c/3 - a/6)*x^3 - (b*x^2)/2 + (a + c)*x + b
如果想了解更多泰勒定理的应用,可以参考这篇文章: