试图在Matlab中计算e ^ 10的部分和? [英] Trying to calculate partial sums of e^10 in Matlab?
本文介绍了试图在Matlab中计算e ^ 10的部分和?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经编写了函数:
function [sum] = func(a,b)
sum = 0;
for i = 0:b
sum = sum + ((a.^i)/(factorial(i)));
end
在控制台中,我给出的命令是:
In the console, the commands I give are:
>> x = [10:10:100]
x =
10 20 30 40 50 60 70 80 90 100
然后我得到:
>> y = func(10,x)
y =
1.2842e+04
为什么我没有得到病媒?为什么这个数字这么大(应该接近10)? 任何帮助将不胜感激!
Why am I not getting a vector? And why is the number so big (it's supposed to be close to 10)? Any help would be appreciated!
推荐答案
f = @(x,i) (x.^i)./factorial(i)
r=f(10,0:50); %50 terms in taylor series more than enough for good approx.
cumsum(r)
1.0e+04 *
0.0001
0.0011
0.0061
0.0228
....
2.202646579479054
2.202646579480280
验证
>> exp(10)
2.202646579480672e+04
这篇关于试图在Matlab中计算e ^ 10的部分和?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文