⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 epprox.txt

📁 这是《Numerical Methods with MATLAB: Implementation and Application》一书的配书程序(Matlab)
💻 TXT
字号:
function epprox
% epprox  Demonstrate catastrophic cancellation in evaluation of
%         e = exp(1) = lim_{n->infinity} (1 + 1/n)^n
%
% Synopsis:  y = epprox
%
% Input:     none
%
% Output:    Table comparing exp(1) and f(n) = (1 + 1/n)^n as n -> infinity

%  Ref:  N.J. Higham, Accuracy and Stability of Numerical Algorithms,
%        1996, SIAM, section 1.11

e = exp(1);
fprintf('\n    n          f(n)              error\n');
for n=logspace(0,16,9)
   f = (1+1/n)^n;
   fprintf('%9.1e  %14.10f  %14.10f\n',n,f,abs(f-e));
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -