mathematica animate命令的使用与泰勒展开和插值

来源:互联网 发布:ubuntu安装postgresql 编辑:程序博客网 时间:2024/05/20 18:19

手把手教你如何用mathematica做泰勒逼近

1、 问题

任给一个函数,做出其泰勒逼近图像;做出的插值逼近图像,观察其插值误差是否随着插值点的增加而减少。

2、 方法

由泰勒公式,自定义一个任意函数的泰勒展开函数(mathematica中含有相应的函数,但为了体验函数定义的用法,故自定义),控制展开项数,绘制动态图像,观察其逼近情况;给定函数的左右端点,使用Table循环生成给定点数的插值点,使用Interpolation产生插值函数,绘图。

3、 程序


Animate[f = Sin[x];(*任给一个函数*) taylor[f_, x0_, n_] :=   Sum[(D[f, {x, k}]; D[f, {x, k}] /. x -> x0)/k!*(x - x0)^k, {k, 0,     n}];(*定义泰勒展开函数*)figure = taylor[f, 0, m]; Plot[{figure, f}, {x, -10 Pi, 10 Pi}, PlotRange -> 2](*绘图*), {m, 0,   90}]Animate[f = 1/(1 + x^2); r = 5; g1 = Plot[f, {x, -r, r}, PlotStyle -> RGBColor[1, 0, 0]]; p0 = Table[{x0, f /. x -> x0}, {x0, -r, r, 2 r/n}]; Interf = Interpolation[p0, InterpolationOrder -> n]; g2 = Plot[Interf[x], {x, -r, r}, PlotStyle -> RGBColor[0, 0, 1]]; Show[g1, g2, PlotRange -> {{-r, r}, {-0.8, 2}}], {n, 1, 60, 2}]


4、结果

0 0