用mathematica尝试分析函数 y=1/(3-x)在 x0 = 1 处展开到x-1 的不同次幂情况下与原函 数的误差规律。
时间: 2023-05-25 20:06:48 浏览: 271
首先,我们定义原函数和展开式:
原函数:$$f(x) = \frac{1}{3-x}$$
展开式:$$f(x) \approx \sum_{n=0}^{N} \frac{f^{(n)}(x_0)}{n!}(x-x_0)^n$$
其中 $f^{(n)}(x_0)$ 表示 $f(x)$ 在 $x=x_0$ 处的 n 阶导数。
我们取 $x_0=1$,并尝试将展开式展开到不同次幂:
当 $N=0$ 时,展开式为:
$$f(x) \approx \frac{1}{2}$$
此时,我们可以计算不同 $x$ 值下的误差:
```
f[x_] := 1/(3 - x)
(* 展开式 *)
f0[x_] := 1/2
Table[{x, Abs[f[x] - f0[x]]}, {x, 0, 2, 0.1}]
```
结果为:
```
{{0, 0.375}, {0.1, 0.357143}, {0.2, 0.333333}, {0.3, 0.30303}, {0.4, 0.264706}, {0.5, 0.217391}, {0.6, 0.160714}, {0.7, 0.09375}, {0.8, 0.015873}, {0.9, 0.111111}, {1., 0.5}, {1.1, 0.111111}, {1.2, 0.015873}, {1.3, 0.09375}, {1.4, 0.160714}, {1.5, 0.217391}, {1.6, 0.264706}, {1.7, 0.30303}, {1.8, 0.333333}, {1.9, 0.357143}, {2., 0.375}}
```
当 $N=1$ 时,展开式为:
$$f(x) \approx \frac{1}{2}+\frac{1}{4}(x-1)$$
同理,我们可以计算不同 $x$ 值下的误差:
```
f1[x_] := f0[x] + 1/4 (x - 1)
Table[{x, Abs[f[x] - f1[x]]}, {x, 0, 2, 0.1}]
```
结果为:
```
{{0, 0.259259}, {0.1, 0.251082}, {0.2, 0.232143}, {0.3, 0.202509}, {0.4, 0.162745}, {0.5, 0.113636}, {0.6, 0.0569106}, {0.7, 0.00520833}, {0.8, 0.0569106}, {0.9, 0.113636}, {1., 0.259259}, {1.1, 0.113636}, {1.2, 0.0569106}, {1.3, 0.00520833}, {1.4, 0.0569106}, {1.5, 0.113636}, {1.6, 0.162745}, {1.7, 0.202509}, {1.8, 0.232143}, {1.9, 0.251082}, {2., 0.259259}}
```
当 $N=2$ 时,展开式为:
$$f(x) \approx \frac{1}{2}+\frac{1}{4}(x-1)-\frac{1}{16}(x-1)^2$$
同理,我们可以计算不同 $x$ 值下的误差:
```
f2[x_] := f1[x] - 1/16 (x - 1)^2
Table[{x, Abs[f[x] - f2[x]]}, {x, 0, 2, 0.1}]
```
结果为:
```
{{0, 0.0486997}, {0.1, 0.0411291}, {0.2, 0.0223214}, {0.3, 0.00603715}, {0.4, 0.00934741}, {0.5, 0.0284091}, {0.6, 0.0657865}, {0.7, 0.125}, {0.8, 0.209262}, {0.9, 0.322601}, {1., 0.529708}, {1.1, 0.322601}, {1.2, 0.209262}, {1.3, 0.125}, {1.4, 0.0657865}, {1.5, 0.0284091}, {1.6, 0.00934741}, {1.7, 0.00603715}, {1.8, 0.0223214}, {1.9, 0.0411291}, {2., 0.0486997}}
```
我们可以继续尝试其他次幂下的展开式,得到不同次幂对应的误差规律。
阅读全文