【MATLAB】【公式验证】泰勒级数

本文通过MATLAB演示了泰勒级数在指数函数和三角函数上的拟合效果,展示随着项数增加如何提高拟合精度。分析表明,在特定区间内,适当增加项数能有效逼近原函数。例如,指数函数在(0,5)区间用十项即可深度拟合,而三角函数在(-π,π)区间用四项达到深度拟合。但随着区间扩大,需增加项数以保持拟合质量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

泰勒级数

关于泰勒级数的概念和工程意义在这不再叙述,此文章只是用matlab把图形拟合出来,让读者形象地感受随着项数的增加,函数拟合效果逐渐逼近。
常见的函数泰勒展开:
请添加图片描述

指数函数

三项拟合效果:

x=0:0.01:5;
y1=exp(x);
y2=1+x+1/factorial(2)*power(x,2)+1/factorial(3)*power(x,3);
plot(x,y1,x,y2);
xlabel('x')
ylabel('y')

在这里插入图片描述
五项拟合效果:

x=0:0.01:5;
y1=exp(x);
y2=1+x+1/factorial(2)*power(x,2)+1/factorial(3)*power(x,3)+1/factorial(4)*power(x,4)+1/factorial(5)*power(x,5);
plot(x,y1,x,y2);
xlabel('x')
ylabel('y')

在这里插入图片描述
十项拟合效果:

x=0:0.01:5;
y1=exp(x);
y2=1+x+1/factorial(2)*power(x,2)+1/factorial(3)*power(x,3)+1/factorial(4)*power(x,4)+1/factorial(5)*power(x,5)+1/factorial(6)*power(x,6)+1/factorial(7)*power(x,7)+1/factorial(8)*power(x,8)+1/factorial(9)*power(x,9)+1/factorial(10)*power(x,10);
plot(x,y1,x,y2);
xlabel('x')
ylabel('y')

在这里插入图片描述
以上分析,当有十项时,在(0,5)区间上已经深度拟合了,但是随着区间的增加,必须要增加项数才能“跟得上”原函数的变化。
例如区间增大到10:

x=0:0.01:10;
y1=exp(x);
y2=1+x+1/factorial(2)*power(x,2)+1/factorial(3)*power(x,3)+1/factorial(4)*power(x,4)+1/factorial(5)*power(x,5)+1/factorial(6)*power(x,6)+1/factorial(7)*power(x,7)+1/factorial(8)*power(x,8)+1/factorial(9)*power(x,9)+1/factorial(10)*power(x,10);
plot(x,y1,x,y2);
xlabel('x')
ylabel('y')

在这里插入图片描述

三角函数

二项拟合:

x=-pi:0.01:pi;
y1=sin(x);
y2=x-power(x,3)/factorial(3);
plot(x,y1,x,y2);
xlabel('x')
ylabel('y')

在这里插入图片描述
三项拟合:

x=-pi:0.01:pi;
y1=sin(x);
y2=x-power(x,3)/factorial(3)+power(x,5)/factorial(5);
plot(x,y1,x,y2);
xlabel('x')
ylabel('y')

在这里插入图片描述
四项拟合:

x=-pi:0.01:pi;
y1=sin(x);
y2=x-power(x,3)/factorial(3)+power(x,5)/factorial(5)-power(x,7)/factorial(7);
plot(x,y1,x,y2);
xlabel('x')
ylabel('y')

在这里插入图片描述
以上分析,当有四项时,在(-pi,pi)区间上已经深度拟合了,但是随着区间的增加,必须要增加项数才能“跟得上”原函数的变化。
例如区间增大到(-4,4):

x=-4:0.01:4;
y1=sin(x);
y2=x-power(x,3)/factorial(3)+power(x,5)/factorial(5)-power(x,7)/factorial(7);
plot(x,y1,x,y2);
xlabel('x')
ylabel('y')

在这里插入图片描述

总结

数学是如此的奇妙!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值