Condition Overview — Condition Overview
These functions provides the condition number of various elementary functions. Their goal is to evaluate the potential numerical difficulty of evaluating numerically a function at a given point.
Consider a smooth function f defined by:
where x and y are a real numbers.
The condition number is a measure of the sensitivity of the output y with respect to the input x. It is the ratio of the relative error on y and the relative error on x. For a smooth scalar function f, it is equal to:
It is possible to express the condition number of the inverse of a function, depending on its derivative. Indeed, the derivative of the inverse function of f satisfies:
The condition number of the inverse function is then:
For several elementary functions, we provide the exact condition number.
In the case where the condition number is not provided, the user may call the
condnb_condnum
function, which uses finite differences to
estimate it.
In general, we do not provide the exact condition number of a function.
In this case, we may use the condnb_condnum
function, which uses finite differences to
estimate it.
In the following example, we compute the condition number of the sin function.
[ c , y ] = condnb_condnum ( sin , 1.e-100 ) // c~1 [ c , y ] = condnb_condnum ( sin , 3.14159 ) // c ~10^6 [ c , y ] = condnb_condnum ( sin , 3.141592653 ) // c ~10^9 [ c , y ] = condnb_condnum ( sin , 3.1415926535898 ) // c ~10^14 [ c , y ] = condnb_condnum ( sin , %pi ) // c ~10^16
The condnb_sincond
function provides the exact condition number of the
sin function.
In the following example, we compute the condition number of the sin function
for various values of x.
[ c , y ] = condnb_sincond ( 1.e-100 ) // c~1 [ c , y ] = condnb_sincond ( 3.14159 ) // c ~10^6 [ c , y ] = condnb_sincond ( 3.141592653 ) // c ~10^9 [ c , y ] = condnb_sincond ( 3.1415926535898 ) // c ~10^14 [ c , y ] = condnb_sincond ( %pi ) // c ~10^16
The condition number of a function may evolve wildly while the input
argument x
varies in its definition range.
In order to analyse the global behavior of the condition number, we may be interested
by plotting the function value and compare with the condition number in a given interval.
The condition values of acos are positive and of very different magnitudes :
automatically switches to log scale.
scf(); condnb_plotcond ( "acos" , linspace(-1,1,1000) );
This produces the following output.
In this section, we analyze the condition number of the normal standard distribution function and its inverse.
Condition number of Inverse normal standard distribution function / p
function x = myinvnorstd ( p ) mu = zeros(p) std = ones(p) q = 1-p x = cdfnor("X",mu,std,p,q) endfunction p = linspace(1e-5,1-1e-5,1000); for k = 1 : size(p,"*") c(k) = condnb_condnum(myinvnorstd,p(k)); end h = scf(); plot(p,c) h.children.log_flags="nln"; xtitle("Conditionning of Inverse Normal Standard","p","Condition Number");
Condition number of Inverse normal standard distribution function / q Notice that, when the function is ill-conditionned for p close to 1, then it is well conditionned with respect to q, which is close to 0. The only unavoidable ill-conditionned point is p~q~0.5, since both p and q make the function ill-conditionned.
function x = myinvnorstdq ( q ) mu = zeros(q) std = ones(q) p = 1-q x = cdfnor("X",mu,std,p,q) endfunction q = linspace(1e-5,1-1e-5,1000); for k = 1 : size(q,"*") c(k) = condnb_condnum(myinvnorstdq,q(k)); end h = scf(); plot(q,c) h.children.log_flags="nln"; xtitle("Conditionning of Inverse Normal Standard","q","Condition Number");
The previous script produces the following plot.
Condition number of normal standard distribution function / p. Notice that the standard normal CDF is equal to zero as soon as x is smaller than -40. The condition number is never greater than 1.e4, which is not very large, but should be noticed in accuracy tests. The symetric behaviour will be observed with respect to q.
function p = mynorstd ( x ) mu = zeros(x) std = ones(x) p=cdfnor("PQ",x,mu,std) endfunction h = scf(); subplot(2,1,1); x = linspace(-40,10,1000); p = mynorstd ( x ); plot(x,p); for k = 1 : size(x,"*") c(k) = condnb_condnum(mynorstd,x(k)); end subplot(2,1,2); plot(x,c) xtitle("Conditionning of Normal Standard","x","Condition Number"); h.children(1).y_location = "left"; h.children(2).y_location = "left";
The previous script produces the following plot.
"Accuracy and Stability of Numerical Algorithms", Nicholas J. Higham, Society for Industrial and Applied Mathematics, Philadelphia, PA, USA, Second Edition, 2002
"Rounding errors in algebraic processes", James Hardy Wilkinson, 1963, Prentice Hall
"Handbook of Floating-Point Arithmetic", Muller, Brisebarre, de Dinechin, Jeannerod, Lefevre, Melquiond, Revol, Stehle, Torres, Birkhauser Boston, 2010