assert_condition2reltol — Suggests a relative error, computed from the condition number.
rtol = assert_condition2reltol ( condition ) rtol = assert_condition2reltol ( condition , offset )
a matrix of doubles, the condition number. The condition number must be strictly positive.
a matrix of doubles, an shift for the number of required digits. offset=1 produces a larger relative tolerance by a factor 10^1, offset=-1 produces a smaller relative tolerance by a factor 10^-1.
a matrix of doubles, the relative tolerance. The relative tolerance is strictly positive, lower than 1.
Depending on the condition number, returns the corresponding relative tolerance. We emphasize that this relative tolerance is only a suggestion. Indeed, there may be correct reasons of using a lower or a higher relative tolerance.
Any scalar input argument is expanded to a matrix of doubles of the same size as the other input arguments.
The algorithm is the following. We compute the base-10 logarithm of condition, then add the offset. This number represents the expected number of lost digits. We project it into the interval [0,dmax], where dmax -log10(2^(-53)) is the maximum achievable number of accurate digits for doubles. We compute the number of required digits d, by difference between dmax and the number of lost digits. Then the relative tolerance is 10^-d.
rtol = assert_condition2reltol ( 0 ) // 1.110D-16 rtol = assert_condition2reltol ( 1 ) // 1.110D-16 rtol = assert_condition2reltol ( 1.e1 ) // 1.110D-15 rtol = assert_condition2reltol ( 1.e2 ) // 1.110D-14 rtol = assert_condition2reltol ( 1.e3 ) // 1.110D-13 rtol = assert_condition2reltol ( 1.e16 ) // 1 rtol = assert_condition2reltol ( 1.e17 ) // 1 rtol = assert_condition2reltol ( 1.e18 ) // 1 // Matrix input. rtol = assert_condition2reltol ( 0 ) // Using offset // Positive offset : increase relative tolerance (requires less accuracy) assert_condition2reltol ( 1.e2 , [0 1] ) // [1.1D-14 1.1D-13] // Negative offset : decrease relative tolerance (requires more accuracy) // See that the impact of offset is limited. assert_condition2reltol ( 1.e2 , [0 -1 -2 -3] ) // [1.1D-14 1.1D-15 1.1D-16 1.1D-16] // Positive offset // See that the impact of offset is limited. assert_condition2reltol ( 1.e14 , [0 1 2 3] ) // [1.1D-02 1.1D-01 1 1]