??泰勒公式得名于英国数学家鲁克·泰勒,可以大致描述为:如果函数足够平滑,并且在已知函数在某一点的各阶导数值的情况下,函数在一个点的邻域内的值可以用函数在该点的值及各阶导数值组成的无穷级数表示出来。如果用一句话描述,就是用多项式去逼近光滑函数。
??泰勒公式最直接的应用就是近似计算,一阶泰勒展开式经常应用于机器学习的最优化算法,比如常见的梯度下降法。
泰勒公式的定义 ??若函数 f ( x ) f(x) f(x)在包含 x 0 x_0 x0?的区间[a,b]上具有n阶导数,并且在开区间(a,b)上n+1次可导,那么对于闭区间[a,b]上的任意x都有: f ( x ) = f ( x 0 ) 0 ! + f ′ ( x 0 ) 1 ! ( x ? x 0 ) + … + f ( n ) ( x 0 ) n ! ( x ? x 0 ) n + R n ( x ) = ∑ n = 0 N f ( n ) ( x 0 ) n ! ( x ? x 0 ) n + R n ( x ) \begin{aligned} f(x)&=\frac{f(x_0)}{0!}+\frac{f^{\prime}(x_0)}{1!}(x-x_0)+\ldots+\frac{f^{(n)}(x_0)}{n!}(x-x_0)^n+R_n(x) \\ &=\sum_{n=0}^N\frac{f^{(n)}(x_0)}{n!}(x-x_0)^n+R_n(x) \end{aligned} f(x)?=0!f(x0?)?+1!f′(x0?)?(x?x0?)+…+n!f(n)(x0?)?(x?x0?)n+Rn?(x)=n=0∑N?n!f(n)(x0?)?(x?x0?)n+Rn?(x)?其中, f ( n ) ( x 0 ) f^{(n)}(x_0) f(n)(x0?)表示 f ( x ) f(x) f(x)的n阶导数。等号后的多项式称为函数 f ( x ) f(x) f(x)在 x 0 x_0 x0?处的泰勒展开式,剩余的 R n ( x ) R_n(x) Rn?(x)叫做泰勒公式的余项,是 ( x ? x 0 ) n (x-x_0)^n (x?x0?)n的高阶无穷小。
??常见的泰勒公式余项是拉格朗日余项,公式如下:
R n ( x ) = f ( n + 1 ) ( ξ ) ( n + 1 ) ! ( x ? x 0 ) n + 1,x 0 < ξ < x R_n(x)=\frac{f^{(n+1)}(\xi)}{(n+1)!}(x-x_0)^{n+1}\ ,\ x_0<\xi
泰勒公式的推导 ??我们知道,根据拉格朗日中值定理导出的有限增量定理有:
lim ? Δ x → 0 ( f ( x 0 + Δ x ) ? f ( x 0 ) ) = f ′ ( x 0 ) Δ x \lim_{\Delta x\rightarrow0}(f(x_0+\Delta x)-f(x_0))=f^{\prime}(x_0)\Delta x Δx→0lim?(f(x0?+Δx)?f(x0?))=f′(x0?)Δx
??于是:
?? f ( x ) = f ( x 0 ) + f ′ ( x 0 ) ( x ? x 0 ) + α f(x)=f(x_0)+f^{\prime}(x_0)(x-x_0)+\alpha f(x)=f(x0?)+f′(x0?)(x?x0?)+α
??其中误差 α \alpha α是在 Δ x → 0 \Delta x \rightarrow 0 Δx→0的前提下才趋向于0,所以在近似计算中往往不够精确。于是我们需要一个能够足够精确的且能估计出误差的多项式: P ( x ) = A 0 + A 1 ( x ? x 0 ) + A 2 ( x ? x 0 ) 2 + … + A n ( x ? x 0 ) n P(x)=A_0+A_1(x-x_0)+A_2(x-x_0)^2+\ldots+A_n(x-x_0)^n P(x)=A0?+A1?(x?x0?)+A2?(x?x0?)2+…+An?(x?x0?)n
来近似地表示函数 f ( x ) f(x) f(x)且要写出其误差 f ( x ) ? P ( x ) f(x)-P(x) f(x)?P(x)的具体表达式。
??首先假设在一点 x 0 x_0 x0?处, P ( x ) P(x) P(x)和 f ( x ) f(x) f(x)的值是相等的,而且它们的相同阶导数值也是相等的,即函数 P ( x ) P(x) P(x)满足下列等式:
P ( x 0 ) = f ( x 0 ) P ′ ( x 0 ) = f ′ ( x 0 ) P ′ ′ ( x 0 ) = f ′ ′ ( x 0 ) … P ( n ) ( x 0 ) = f ( n ) ( x 0 ) \begin{aligned} P(x_0)&=f(x_0) \\ P^{\prime}(x_0)&=f^{\prime}(x_0) \\ P^{\prime\prime}(x_0)&=f^{\prime\prime}(x_0) \\ &\ldots \\ P^{(n)}(x_0)&=f^{(n)}(x_0) \\ \end{aligned} P(x0?)P′(x0?)P′′(x0?)P(n)(x0?)?=f(x0?)=f′(x0?)=f′′(x0?)…=f(n)(x0?)?
??于是可以依次求出 A 0 、 A 1 、 A 2 、 … 、 A n A_0、A_1、A_2、\ldots 、A_n A0?、A1?、A2?、…、An?,显然有:
P ( x 0 ) = A 0 , 所 以 A 0 = f ( x 0 ) P ′ ( x 0 ) = A 1 , 所 以 A 1 = f ′ ( x 0 ) P ′ ′ ( x 0 ) = 2 ! A 2 , 所 以 A 2 = f ′ ′ ( x 0 ) 2 ! ; … P ( n ) ( x 0 ) = n ! A n , 所 以 A n = f ( n ) ( x 0 ) n ! \begin{aligned} &P(x_0)=A_0 ,所以A_0=f(x_0) \\ &P^{\prime}(x_0)=A_1,所以A_1=f^{\prime}(x_0) \\ &P^{\prime\prime}(x_0)=2!A_2,所以A_2=\frac{f^{\prime\prime}(x_0)}{2!}; \\ &\ldots \\ &P^{(n)}(x_0)=n!A_n,所以 A_n=\frac{f^{(n)}(x_0)}{n!}\\ \end{aligned} ?P(x0?)=A0?,所以A0?=f(x0?)P′(x0?)=A1?,所以A1?=f′(x0?)P′′(x0?)=2!A2?,所以A2?=2!f′′(x0?)?;…P(n)(x0?)=n!An?,所以An?=n!f(n)(x0?)??
??至此,多项式的各项系数都已求出,得:
P ( x ) = f ( x 0 ) 0 ! + f ′ ( x 0 ) 1 ! ( x ? x 0 ) + … + f ( n ) ( x 0 ) n ! ( x ? x 0 ) n P(x)=\frac{f(x_0)}{0!}+\frac{f^{\prime}(x_0)}{1!}(x-x_0)+\ldots+\frac{f^{(n)}(x_0)}{n!}(x-x_0)^n P(x)=0!f(x0?)?+1!f′(x0?)?(x?x0?)+…+n!f(n)(x0?)?(x?x0?)n
??以上就是函数的泰勒展开式。
??接下来就要求误差的具体表达式了,首先,令误差为: R n ( x ) = f ( x ) ? P ( x ) R_n(x)=f(x)-P(x) Rn?(x)=f(x)?P(x)
??设 f ( x ) f(x) f(x)在定义域内n+1阶可导, R n ( x ) R_n(x) Rn?(x)为 ( x ? x 0 ) (x-x_0) (x?x0?)的n+1阶无穷小。若 x = x 0 x=x_0 x=x0?,则:
R n ( x 0 ) = f ( x 0 ) ? P ( x 0 ) = 0 R_n(x_0)=f(x_0)-P(x_0)=0 Rn?(x0?)=f(x0?)?P(x0?)=0
??进而:
R n ( x 0 ) = R n ′ ( x 0 ) = R n ′ ′ ( x 0 ) = … = R n ( n ) ( x 0 ) = 0 R_n(x_0)=R^{\prime}_n(x_0)=R^{\prime\prime}_n(x_0)=\ldots=R^{(n)}_n(x_0)=0 Rn?(x0?)=Rn′?(x0?)=Rn′′?(x0?)=…=Rn(n)?(x0?)=0
??根据柯西中值定理:
R n ( x ) ( x ? x 0 ) n + 1 = R n ( x ) ? 0 ( x ? x 0 ) n + 1 ? 0 = R n ( x ) ? R n ( x 0 ) ( x ? x 0 ) n + 1 ? ( x 0 ? x 0 ) n + 1 = R n ′ ( ξ 1 ) ( n + 1 ) ( ξ 1 ? x 0 ) n \begin{aligned} \frac{R_n(x)}{(x-x_0)^{n+1}}&=\frac{R_n(x)-0}{(x-x_0)^{n+1}-0} \\ &=\frac{R_n(x)-R_n(x_0)}{(x-x_0)^{n+1}-(x_0-x_0)^{n+1}} \\ &=\frac{R^{\prime}_n(\xi_1)}{(n+1)(\xi_1-x_0)^{n}} \end{aligned} (x?x0?)n+1Rn?(x)??=(x?x0?)n+1?0Rn?(x)?0?=(x?x0?)n+1?(x0??x0?)n+1Rn?(x)?Rn?(x0?)?=(n+1)(ξ1??x0?)nRn′?(ξ1?)??
??其中 ξ 1 ∈ ( x 0 , x ) \xi_1 \in (x_0,x) ξ1?∈(x0?,x),继续使用柯西中值定理得到:
R n ′ ( ξ 1 ) ( n + 1 ) ( ξ 1 ? x 0 ) n = R n ′ ( ξ 1 ) ? 0 ( n + 1 ) ( ξ 1 ? x 0 ) n ? 0 = R n ′ ( ξ 1 ) ? R n ′ ( x 0 ) ( n + 1 ) ( ξ 1 ? x 0 ) n ? ( n + 1 ) ( x 0 ? x 0 ) n = R n ′ ′ ( ξ 2 ) n ( n + 1 ) ( ξ 2 ? x 0 ) n ? 1 \begin{aligned} \frac{R^{\prime}_n(\xi_1)}{(n+1)(\xi_1-x_0)^{n}}&=\frac{R^{\prime}_n(\xi_1)-0}{(n+1)(\xi_1-x_0)^n-0} \\ &=\frac{R^{\prime}_n(\xi_1)-R^{\prime}_n(x_0)}{(n+1)(\xi_1-x_0)^n-(n+1)(x_0-x_0)^n} \\ &=\frac{R^{\prime\prime}_n(\xi_2)}{n(n+1)(\xi_2-x_0)^{n-1}} \end{aligned} (n+1)(ξ1??x0?)nRn′?(ξ1?)??=(n+1)(ξ1??x0?)n?0Rn′?(ξ1?)?0?=(n+1)(ξ1??x0?)n?(n+1)(x0??x0?)nRn′?(ξ1?)?Rn′?(x0?)?=n(n+1)(ξ2??x0?)n?1Rn′′?(ξ2?)??
??其中 ξ 2 ∈ ( x 0 , ξ 1 ) \xi_2 \in (x_0,\xi_1) ξ2?∈(x0?,ξ1?),继续使用n+1次柯西中值定理得到:
R n ( x ) ( x ? x 0 ) n + 1 = R n ( n + 1 ) ( ξ ) ( n + 1 ) ! \frac{R_n(x)}{(x-x_0)^{n+1}}=\frac{R^{(n+1)}_n(\xi)}{(n+1)!} (x?x0?)n+1Rn?(x)?=(n+1)!Rn(n+1)?(ξ)?
??其中 ξ ∈ ( x 0 , ξ n ) \xi \in (x_0,\xi_n) ξ∈(x0?,ξn?),而 ξ n ∈ ( x 0 , x ) \xi_n \in (x_0,x) ξn?∈(x0?,x),同时:
R n ( n + 1 ) ( x ) = f ( n + 1 ) ( x ) ? P ( n + 1 ) ( x ) R n ( n + 1 ) ( ξ ) = f ( n + 1 ) ( ξ ) ? P ( n + 1 ) ( ξ ) \begin{aligned} R^{(n+1)}_n(x)=f^{(n+1)}(x)-P^{(n+1)}(x) \\ R^{(n+1)}_n(\xi)=f^{(n+1)}(\xi)-P^{(n+1)}(\xi) \end{aligned} Rn(n+1)?(x)=f(n+1)(x)?P(n+1)(x)Rn(n+1)?(ξ)=f(n+1)(ξ)?P(n+1)(ξ)?
??而n次多项式 P ( x ) P(x) P(x)的n阶导数 P ( n ) ( x ) P^{(n)}(x) P(n)(x) = 常数,所以 P ( n + 1 ) ( ξ ) = 0 P^{(n+1)}(\xi) =0 P(n+1)(ξ)=0
??进而:
R n ( n + 1 ) ( ξ ) = f ( n + 1 ) ( ξ ) R^{(n+1)}_n(\xi)=f^{(n+1)}(\xi) Rn(n+1)?(ξ)=f(n+1)(ξ)
【如何理解泰勒公式?】??综上可得:
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
推荐阅读
- paddle|动手从头实现LSTM
- 人工智能|干货!人体姿态估计与运动预测
- 推荐系统论文进阶|CTR预估 论文精读(十一)--Deep Interest Evolution Network(DIEN)
- Python专栏|数据分析的常规流程
- 读书笔记|《白话大数据和机器学习》学习笔记1
- Pytorch学习|sklearn-SVM 模型保存、交叉验证与网格搜索
- Python机器学习基础与进阶|Python机器学习--集成学习算法--XGBoost算法
- 深度学习|深度学习笔记总结
- 机器学习|机器学习Sklearn学习总结
- 机器学习|线性回归原理与python实现