Name

condnb_condnum — Computes the empirical condition number of the function f at point x.

Calling Sequence

   [ c , y ] = condnb_condnum ( f , x )
   [ c , y ] = condnb_condnum ( f , x , order )
   [ c , y ] = condnb_condnum ( f , x , order , h )
   
   

Parameters

f :

a function with header y = f(x)

x :

a vector of doubles, the current point

order :

a 1x1 matrix of floating point integers, the order (Default order = 2). Available are order= 1, 2, 4, 6. If order==[], then the default order is used.

h :

a matrix of doubles, the step. Default tries to be optimal for accuracy. If h==[], then the default h is used.

c :

the condition number as the ratio ry/rx

y :

the computed value of f at point x

Description

Computes the condition number by using a finite difference formula.

Any optional input argument equal to the empty matrix is replaced by its default value.

The header of the function f must be

y=f(x)

where x is the current point and y is the function value.

It might happen that the function requires additionnal arguments to be evaluated. In this case, we can use the following feature. The function f can also be the list (fun,a1,a2,...). In this case fun, the first element in the list, must have the header:

y = fun ( x , a1 , a2 , ... )

where the input arguments a1, a2, ... will be automatically be appended at the end of the calling sequence.

Examples

// Show that sin can be ill-conditionned
[ c , y ] = condnb_condnum ( sin , 1.e-100 )         // c~1
// Compare with exact formula :
condnb_sincond(1.e-100)
[ c , y ] = condnb_condnum ( sin , 0 )               // c = nan
[ 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
[ c , y ] = condnb_condnum ( sin , 1.000000357564167061e5 ) // c ~10^16

// An ill-conditionned case for the sum.
xl = 10^(1:15);
x = [-xl xl+0.1];
yExpected = 1.5
[ c , y ] = condnb_condnum ( sum , x )
// Compare with exact formula :
cExpected = condnb_sumcond(x) // c~10^15

// Check various finite difference orders for the sqrt function.
// The condition number is 0.5.
cc = condnb_condnum ( sqrt , 1 , 1 )
// Compare with exact formula :
cc = condnb_sqrtcond ( 1 )
cc = condnb_condnum ( sqrt , 1 , 2 )
cc = condnb_condnum ( sqrt , 1 , 4 )
cc = condnb_condnum ( sqrt , 1 , 6 )
// Make a loop
x = 1.;
order = [1 2 4 6];
for k = 1:4
cc = condnb_condnum ( sqrt , x , order(k) );
ce = sqrtcond ( x );
disp([order(k) cc ce])
end

// Use default order, but configure h
[cc,yc] = condnb_condnum ( sqrt , 1 , [] , 1.e-8 )
// Use default order and h
[cc,yc] = condnb_condnum ( sqrt , 1 , [] , [] )
// Set order, use default h
[cc,yc] = condnb_condnum ( sqrt , 1 , 4 , [] );

   

Authors

Michael Baudin, Digiteo, 2010