#! /usr/bin/env python # def downshift ( n ): #*****************************************************************************80 # ## DOWNSHIFT returns the DOWNSHIFT matrix. # # Formula: # # if ( I-J == 1 mod ( n ) ) # A(I,J) = 1 # else # A(I,J) = 0 # # Example: # # N = 4 # # 0 0 0 1 # 1 0 0 0 # 0 1 0 0 # 0 0 1 0 # # Rectangular properties: # # A is integral: int ( A ) = A. # # A is a zero/one matrix. # # Square Properties: # # A is generally not symmetric: A' /= A. # # A is nonsingular. # # A is a permutation matrix. # # det ( A ) = (-1)^(N-1) # # A is persymmetric: A(I,J) = A(N+1-J,N+1-I). # # A is a Hankel matrix: constant along anti-diagonals. # # A is an N-th root of the identity matrix. # Therefore, the inverse of A = A^(N-1). # # Any circulant matrix generated by a column vector v can be regarded as # the Krylov matrix ( v, A*v, A^2*V, ..., A^(N-1)*v). # # The inverse of A is the upshift operator. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 23 January 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer N, the number of rows and columns of the matrix. # # Output, real A(N,N), the matrix. # import numpy as np from i4_modp import i4_modp a = np.zeros ( [ n, n ] ) for i in range ( 0, n ): for j in range ( 0, n ): if ( i4_modp ( i - j, n ) == 1 ): a[i,j] = 1.0 return a def downshift_condition ( n ): #*****************************************************************************80 # ## DOWNSHIFT_CONDITION computes the L1 condition of the DOWNSHIFT matrix. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 07 February 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer N, the order of the matrix. # # Output, real VALUE the L1 condition. # a_norm = 1.0 b_norm = 1.0 value = a_norm * b_norm return value def downshift_condition_test ( ): #*****************************************************************************80 # ## DOWNSHIFT_CONDITION_TEST tests DOWNSHIFT_CONDITION. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 07 February 2015 # # Author: # # John Burkardt # import platform from downshift import downshift from r8mat_print import r8mat_print print ( '' ) print ( 'DOWNSHIFT_CONDITION_TEST' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' DOWNSHIFT_CONDITION computes the DOWNSHIFT condition.' ) m = 5 n = m a = downshift ( n ) r8mat_print ( m, n, a, ' DOWNSHIFT matrix:' ) value = downshift_condition ( n ) print ( ' Value = %g' % ( value ) ) # # Terminate. # print ( '' ) print ( 'DOWNSHIFT_CONDITION_TEST' ) print ( ' Normal end of execution.' ) return def downshift_determinant ( n ): #*****************************************************************************80 # ## DOWNSHIFT_DETERMINANT computes the determinant of the DOWNSHIFT matrix. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 23 January 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer N, the order of the matrix. # # Output, real DETERM, the determinant. # if ( ( n % 2 ) == 0 ): determ = - 1.0 else: determ = 1.0 return determ def downshift_determinant_test ( ): #*****************************************************************************80 # ## DOWNSHIFT_DETERMINANT_TEST tests DOWNSHIFT_DETERMINANT. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 23 January 2015 # # Author: # # John Burkardt # import platform from downshift import downshift from r8mat_print import r8mat_print print ( '' ) print ( 'DOWNSHIFT_DETERMINANT_TEST' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' DOWNSHIFT_DETERMINANT computes the DOWNSHIFT determinant.' ) m = 5 n = m a = downshift ( n ) r8mat_print ( m, n, a, ' DOWNSHIFT matrix:' ) value = downshift_determinant ( n ) print ( ' Value = %g' % ( value ) ) # # Terminate. # print ( '' ) print ( 'DOWNSHIFT_DETERMINANT_TEST' ) print ( ' Normal end of execution.' ) return def downshift_inverse ( n ): #*****************************************************************************80 # ## DOWNSHIFT_INVERSE returns the inverse of the DOWNSHIFT matrix. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 17 March 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer N, the order of the matrix. # # Output, real A(N,N), the inverse. # from upshift import upshift a = upshift ( n ) return a def downshift_test ( ): #*****************************************************************************80 # ## DOWNSHIFT_TEST tests DOWNSHIFT. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 23 January 2015 # # Author: # # John Burkardt # import platform from r8mat_print import r8mat_print print ( '' ) print ( 'DOWNSHIFT_TEST' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' DOWNSHIFT computes the DOWNSHIFT matrix.' ) m = 5 n = m a = downshift ( n ) r8mat_print ( m, n, a, ' DOWNSHIFT matrix:' ) # # Terminate. # print ( '' ) print ( 'DOWNSHIFT_TEST' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) downshift_test ( ) timestamp ( )