2020-11-10
实验目的
对 e x e^x ex进行泰勒展开,探究展开阶数 n n n为5,6,7,8的情况下, x x x的值为1,-1,5,-5时,展开式的值与实际值之间的误差。
实验步骤
定义一个带两个参数为泰勒展开函数,第一个参数为展开的次数,第二个参数为指数函数的自变量。
def expTaylor(n,x):
y = 1.0
for i in range (1,n+1):
y = y + math.pow(x,i) / math.factorial(i)在这里插入图片描述
return y
实验结果
我把展开的项数都设成1-100,并作图表示出来。
![在这里插入图片描述](https://img-blog.csdnimg.cn/2020111611204281.png?x-oss-process=image/watermark,type_ZmFuZ3p