#! /usr/bin/env python # def cond_test ( ): #*****************************************************************************80 # ## COND_TEST tests COND. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 06 July 2015 # # Author: # # John Burkardt # import numpy as np import platform from combin import combin from combin import combin_inverse from conex1 import conex1 from conex1 import conex1_inverse from conex2 import conex2 from conex2 import conex2_inverse from conex3 import conex3 from conex3 import conex3_inverse from conex4 import conex4 from conex4 import conex4_inverse from kahan import kahan from kahan import kahan_inverse from r8mat_norm_l1 import r8mat_norm_l1 from r8mat_uniform_01 import r8mat_uniform_01 m_test = np.array ( [ 10, 1000, 100000 ] ) print ( '' ) print ( 'COND_TEST' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' COND is the condition number estimator built into Python.' ) print ( '' ) print ( ' Matrix Order Condition Estimate' ) print ( '' ) # # Combinatorial matrix. # name = 'Combinatorial' n = 4 alpha = 2.0 beta = 3.0 a = combin ( alpha, beta, n ) a_inverse = combin_inverse ( alpha, beta, n ) a_norm_l1 = r8mat_norm_l1 ( n, n, a ) a_inverse_norm_l1 = r8mat_norm_l1 ( n, n, a_inverse ) cond_l1 = a_norm_l1 * a_inverse_norm_l1 cond2 = np.linalg.cond ( a, 1 ) print ( ' %20s %4d %14.6g %14.6g' % ( name, n, cond_l1, cond2 ) ) # # CONEX1 # name = 'CONEX1' n = 4 alpha = 100.0 a = conex1 ( alpha ) a_inverse = conex1_inverse ( alpha ) a_norm_l1 = r8mat_norm_l1 ( n, n, a ) a_inverse_norm_l1 = r8mat_norm_l1 ( n, n, a_inverse ) cond_l1 = a_norm_l1 * a_inverse_norm_l1 cond2 = np.linalg.cond ( a, 1 ) print ( ' %20s %4d %14.6g %14.6g' % ( name, n, cond_l1, cond2 ) ) # # CONEX2 # name = 'CONEX2' n = 3 alpha = 100.0 a = conex2 ( alpha ) a_inverse = conex2_inverse ( alpha ) a_norm_l1 = r8mat_norm_l1 ( n, n, a ) a_inverse_norm_l1 = r8mat_norm_l1 ( n, n, a_inverse ) cond_l1 = a_norm_l1 * a_inverse_norm_l1 cond2 = np.linalg.cond ( a, 1 ) print ( ' %20s %4d %14.6g %14.6g' % ( name, n, cond_l1, cond2 ) ) # # CONEX3 # name = 'CONEX3' n = 5 a = conex3 ( n ) a_inverse = conex3_inverse ( n ) a_norm_l1 = r8mat_norm_l1 ( n, n, a ) a_inverse_norm_l1 = r8mat_norm_l1 ( n, n, a_inverse ) cond_l1 = a_norm_l1 * a_inverse_norm_l1 cond2 = np.linalg.cond ( a, 1 ) print ( ' %20s %4d %14.6g %14.6g' % ( name, n, cond_l1, cond2 ) ) # # CONEX4 # name = 'CONEX4' n = 4 a = conex4 ( ) a_inverse = conex4_inverse ( ) a_norm_l1 = r8mat_norm_l1 ( n, n, a ) a_inverse_norm_l1 = r8mat_norm_l1 ( n, n, a_inverse ) cond_l1 = a_norm_l1 * a_inverse_norm_l1 cond2 = np.linalg.cond ( a, 1 ) print ( ' %20s %4d %14.6g %14.6g' % ( name, n, cond_l1, cond2 ) ) # # KAHAN # name = 'KAHAN' n = 4 alpha = 0.25 a = kahan ( alpha, n, n ) a_inverse = kahan_inverse ( alpha, n ) a_norm_l1 = r8mat_norm_l1 ( n, n, a ) a_inverse_norm_l1 = r8mat_norm_l1 ( n, n, a_inverse ) cond_l1 = a_norm_l1 * a_inverse_norm_l1 cond2 = np.linalg.cond ( a, 1 ) print ( ' %20s %4d %14.6g %14.6g' % ( name, n, cond_l1, cond2 ) ) # # Random # seed = 123456789 for j in range ( 0, 5 ): name = 'RANDOM' n = 4 a, seed = r8mat_uniform_01 ( n, n, seed ) a_inverse = np.linalg.inv ( a ) a_norm_l1 = r8mat_norm_l1 ( n, n, a ) a_inverse_norm_l1 = r8mat_norm_l1 ( n, n, a_inverse ) cond_l1 = a_norm_l1 * a_inverse_norm_l1 cond2 = np.linalg.cond ( a, 1 ) print ( ' %20s %4d %14.6g %14.6g' % ( name, n, cond_l1, cond2 ) ) # # Terminate. # print ( '' ) print ( 'COND_TEST' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) cond_test ( ) timestamp ( )