www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/AvoidRoundoffErrorsUsingComplementaryErrorFunctionExample.m

    %% Avoid Roundoff Errors Using Complementary Error Function
% You can use the complementary error function |erfc| in place of
% |1 - erf(x)| to avoid roundoff errors when |erf(x)| is close to |1|.
% 
% Show how to avoid roundoff errors by calculating |1 - erf(10)| using |erfc(10)|.
% The original calculation returns |0| while |erfc(10)| returns the
% correct result.

% Copyright 2015 The MathWorks, Inc.

1 - erf(10)
erfc(10)