www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/SpecifyAbsoluteToleranceUniqueExample.m
%% Specify Absolute Tolerance % By default, |uniquetol| uses a tolerance test of the form |abs(u-v) <= % tol*DS|, where |DS| automatically _scales_ based on the magnitude of the % input data. You can specify a different |DS| value to use with the % |DataScale| option. However, absolute tolerances (where |DS| is a scalar) % do not scale based on the magnitude of the input data. % % First, compare two small values that are a distance |eps| apart. Specify % |tol| and |DS| to make the within tolerance equation: |abs(u-v) <= % 10^-6|. % Copyright 2015 The MathWorks, Inc. x = 0.1; uniquetol([x, exp(log(x))], 10^-6, 'DataScale', 1) %% % Next, increase the magnitude of the values. The round-off error in the % calculation |exp(log(x))| is proportional to the magnitude of the values, % specifically to |eps(x)|. Even though the two large values are a distance % |eps| from one another, |eps(x)| is now much larger. Therefore, |10^-6| % is no longer a suitable tolerance. x = 10^10; uniquetol([x, exp(log(x))], 10^-6, 'DataScale', 1) %% % Correct this issue by using the default (scaled) value of |DS|. format long Y = [0.1 10^10]; uniquetol([Y, exp(log(Y))])