Matlab 函数 fun14:使用麦克劳林公式计算无理数 e 的近似值
function y=fun14(cha) n = 1; temp = 1; sum = 1; while abs(exp(1)-sum) > cha temp = temp * n; sum = sum + 1/temp; n = n + 1; end y = n-1; end
%测试代码 n = 0.001; y = fun14(n); disp(y); %输出6
原文地址: https://www.cveoy.top/t/topic/ofSU 著作权归作者所有。请勿转载和采集!