?? epprox.m
字號:
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
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -