matlab函数求e近似值

如题所述

如何用matlab函数求e近似值?利用e^x的幂级数展开式,再使用for循环语句进行累加计算,可以得到,e的近似值。实现方法为:

Ex=1;

err=1e-5; %计算精度

for n=1:100

    Ex1=Ex+1/factorial(n);

    if  abs(Ex1-Ex)<err

        disp('e的精确值')

        exp(1)

        disp('e的近似值')

        e=Ex

        return

    end

    Ex=Ex1;

end

运行上述代码,可以得到e的近似值(误差小于1e-5)

温馨提示:答案为网友推荐,仅供参考
相似回答