def maxij_plu(n): # *****************************************************************************80 # ## MAXIJ_PLU returns the PLU factors of the MAXIJ matrix. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 23 March 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer N, the order of the matrix. # # Output, real P(N,N), L(N,N), U(N,N), the PLU factors. # import numpy as np from i4_wrap import i4_wrap p = np.zeros((n, n)) for j in range(0, n): for i in range(0, n): if i4_wrap(j - i, 1, n) == 1: p[i, j] = 1.0 l = np.zeros((n, n)) l[0, 0] = 1.0 j = 0 for i in range(1, n): l[i, j] = float(i) / float(n) for j in range(1, n): l[j, j] = 1.0 u = np.zeros((n, n)) for j in range(0, n): u[0, j] = float(n) for i in range(1, n): for j in range(i, n): u[i, j] = float(j + 1 - i) return p, l, u
def maxij_plu(n): #*****************************************************************************80 # ## MAXIJ_PLU returns the PLU factors of the MAXIJ matrix. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 23 March 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer N, the order of the matrix. # # Output, real P(N,N), L(N,N), U(N,N), the PLU factors. # import numpy as np from i4_wrap import i4_wrap p = np.zeros((n, n)) for j in range(0, n): for i in range(0, n): if (i4_wrap(j - i, 1, n) == 1): p[i, j] = 1.0 l = np.zeros((n, n)) l[0, 0] = 1.0 j = 0 for i in range(1, n): l[i, j] = float(i) / float(n) for j in range(1, n): l[j, j] = 1.0 u = np.zeros((n, n)) for j in range(0, n): u[0, j] = float(n) for i in range(1, n): for j in range(i, n): u[i, j] = float(j + 1 - i) return p, l, u
def daub8(n): #*****************************************************************************80 # ## DAUB8 returns the DAUB8 matrix. # # Discussion: # # The DAUB8 matrix is the Daubechies wavelet transformation matrix # with 8 coefficients. # # Properties: # # The family of matrices is nested as a function of N. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 12 January 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer N, the order of the matrix. # N must be at least 8 and a multiple of 2. # # Output, real A(N,N), the matrix. # import numpy as np from math import sqrt from i4_wrap import i4_wrap from sys import exit if (n < 8 or (n % 2) != 0): print '' print 'DAUB8 - Fatal error!' print ' N must be at least 8 and a multiple of 2.' exit('DAUB8 - Fatal error!') a = np.zeros([n, n]) c0 = 0.2303778133088964 c1 = 0.7148465705529154 c2 = 0.6308807679298587 c3 = -0.0279837694168599 c4 = -0.1870348117190931 c5 = 0.0308413818355607 c6 = 0.0328830116668852 c7 = -0.0105974017850690 for i in range(0, n - 1, 2): a[i, i] = c0 a[i, i + 1] = c1 a[i, i4_wrap(i + 2, 0, n - 1)] = c2 a[i, i4_wrap(i + 3, 0, n - 1)] = c3 a[i, i4_wrap(i + 4, 0, n - 1)] = c4 a[i, i4_wrap(i + 5, 0, n - 1)] = c5 a[i, i4_wrap(i + 6, 0, n - 1)] = c6 a[i, i4_wrap(i + 7, 0, n - 1)] = c7 a[i + 1, i] = c7 a[i + 1, i + 1] = -c6 a[i + 1, i4_wrap(i + 2, 0, n - 1)] = c5 a[i + 1, i4_wrap(i + 3, 0, n - 1)] = -c4 a[i + 1, i4_wrap(i + 4, 0, n - 1)] = c3 a[i + 1, i4_wrap(i + 5, 0, n - 1)] = -c2 a[i + 1, i4_wrap(i + 6, 0, n - 1)] = c1 a[i + 1, i4_wrap(i + 7, 0, n - 1)] = -c0 return a
def dif2cyclic(n): #*****************************************************************************80 # ## DIF2CYCLIC returns the cyclic second difference matrix. # # Example: # # N = 5 # # 2 -1 . . -1 # -1 2 -1 . . # . -1 2 -1 . # . . -1 2 -1 # -1 . . -1 2 # # Square Properties: # # A is symmetric: A' = A. # # Because A is symmetric, it is normal. # # Because A is normal, it is diagonalizable. # # A is persymmetric: A(I,J) = A(N+1-J,N+1-I). # # A is centrosymmetric: A(I,J) = A(N+1-I,N+1-J). # # A is a circulant: each row is shifted once to get the next row. # # A is (weakly) row diagonally dominant. # # A is (weakly) column diagonally dominant. # # A is singular. # # det ( A ) = 0. # # (1,1,...,1) is a null vector of A. # # A is cyclic tridiagonal. # # A is Toeplitz: constant along diagonals. # # A has constant row sum = 0. # # A has constant column sum = 0. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 22 January 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer N, the order of A. # # Output, real A(N,N), the matrix. # import numpy as np from i4_wrap import i4_wrap a = np.zeros([n, n]) for i in range(0, n): im1 = i4_wrap(i - 1, 0, n - 1) a[i, im1] = -1.0 a[i, i] = 2.0 ip1 = i4_wrap(i + 1, 0, n - 1) a[i, ip1] = -1.0 return a
def daub6(n): #*****************************************************************************80 # ## DAUB6 returns the DAUB6 matrix. # # Discussion: # # The DAUB6 matrix is the Daubechies wavelet transformation matrix # with 6 coefficients. # # Properties: # # The family of matrices is nested as a function of N. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 11 January 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer N, the order of the matrix. # N must be at least 6 and a multiple of 2. # # Output, real A(N,N), the matrix. # import numpy as np from math import sqrt from i4_wrap import i4_wrap from sys import exit if (n < 6 or (n % 2) != 0): print '' print 'DAUB6 - Fatal error!' print ' N must be at least 6 and a multiple of 2.' exit('DAUB6 - Fatal error!') a = np.zeros([n, n]) c0 = 1.0 + sqrt(10.0) + sqrt(5.0 + sqrt(40.0)) c1 = 5.0 + sqrt(10.0) + 3.0 * sqrt(5.0 + sqrt(40.0)) c2 = 10.0 - sqrt(40.0) + 2.0 * sqrt(5.0 + sqrt(40.0)) c3 = 10.0 - sqrt(40.0) - 2.0 * sqrt(5.0 + sqrt(40.0)) c4 = 5.0 + sqrt(10.0) - 3.0 * sqrt(5.0 + sqrt(40.0)) c5 = 1.0 + sqrt(10.0) - sqrt(5.0 + sqrt(40.0)) c0 = c0 / sqrt(512.0) c1 = c1 / sqrt(512.0) c2 = c2 / sqrt(512.0) c3 = c3 / sqrt(512.0) c4 = c4 / sqrt(512.0) c5 = c5 / sqrt(512.0) for i in range(0, n - 1, 2): a[i, i] = c0 a[i, i + 1] = c1 a[i, i4_wrap(i + 2, 0, n - 1)] = c2 a[i, i4_wrap(i + 3, 0, n - 1)] = c3 a[i, i4_wrap(i + 4, 0, n - 1)] = c4 a[i, i4_wrap(i + 5, 0, n - 1)] = c5 a[i + 1, i] = c5 a[i + 1, i + 1] = -c4 a[i + 1, i4_wrap(i + 2, 0, n - 1)] = c3 a[i + 1, i4_wrap(i + 3, 0, n - 1)] = -c2 a[i + 1, i4_wrap(i + 4, 0, n - 1)] = c1 a[i + 1, i4_wrap(i + 5, 0, n - 1)] = -c0 return a
def daub10(n): #*****************************************************************************80 # ## DAUB10 returns the DAUB10 matrix. # # Discussion: # # The DAUB10 matrix is the Daubechies wavelet transformation matrix # with 10 coefficients. # # Properties: # # The family of matrices is nested as a function of N. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 14 January 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer N, the order of the matrix. # N must be at least 10 and a multiple of 2. # # Output, real A(N,N), the matrix. # import numpy as np from math import sqrt from i4_wrap import i4_wrap from sys import exit if (n < 10 or (n % 2) != 0): print '' print 'DAUB10 - Fatal error!' print ' N must be at least 10 and a multiple of 2.' exit('DAUB10 - Fatal error!') a = np.zeros([n, n]) c = np.array ( [ \ 0.1601023979741929, \ 0.6038292697971895, \ 0.7243085284377726, \ 0.1384281459013203, \ -0.2422948870663823, \ -0.0322448695846381, \ 0.0775714938400459, \ -0.0062414902127983, \ -0.0125807519990820, \ 0.0033357252854738 ] ) for i in range(0, n - 1, 2): a[i, i] = c[0] a[i, i + 1] = c[1] a[i, i4_wrap(i + 2, 0, n - 1)] = c[2] a[i, i4_wrap(i + 3, 0, n - 1)] = c[3] a[i, i4_wrap(i + 4, 0, n - 1)] = c[4] a[i, i4_wrap(i + 5, 0, n - 1)] = c[5] a[i, i4_wrap(i + 6, 0, n - 1)] = c[6] a[i, i4_wrap(i + 7, 0, n - 1)] = c[7] a[i, i4_wrap(i + 8, 0, n - 1)] = c[8] a[i, i4_wrap(i + 9, 0, n - 1)] = c[9] a[i + 1, i] = c[9] a[i + 1, i + 1] = -c[8] a[i + 1, i4_wrap(i + 2, 0, n - 1)] = c[7] a[i + 1, i4_wrap(i + 3, 0, n - 1)] = -c[6] a[i + 1, i4_wrap(i + 4, 0, n - 1)] = c[5] a[i + 1, i4_wrap(i + 5, 0, n - 1)] = -c[4] a[i + 1, i4_wrap(i + 6, 0, n - 1)] = c[3] a[i + 1, i4_wrap(i + 7, 0, n - 1)] = -c[2] a[i + 1, i4_wrap(i + 8, 0, n - 1)] = c[1] a[i + 1, i4_wrap(i + 9, 0, n - 1)] = -c[0] return a
def daub6 ( n ): #*****************************************************************************80 # ## DAUB6 returns the DAUB6 matrix. # # Discussion: # # The DAUB6 matrix is the Daubechies wavelet transformation matrix # with 6 coefficients. # # Properties: # # The family of matrices is nested as a function of N. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 11 January 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer N, the order of the matrix. # N must be at least 6 and a multiple of 2. # # Output, real A(N,N), the matrix. # import numpy as np from math import sqrt from i4_wrap import i4_wrap from sys import exit if ( n < 6 or ( n % 2 ) != 0 ): print '' print 'DAUB6 - Fatal error!' print ' N must be at least 6 and a multiple of 2.' exit ( 'DAUB6 - Fatal error!' ) a = np.zeros ( [ n, n ] ) c0 = 1.0 + sqrt ( 10.0 ) + sqrt ( 5.0 + sqrt ( 40.0 ) ) c1 = 5.0 + sqrt ( 10.0 ) + 3.0 * sqrt ( 5.0 + sqrt ( 40.0 ) ) c2 = 10.0 - sqrt ( 40.0 ) + 2.0 * sqrt ( 5.0 + sqrt ( 40.0 ) ) c3 = 10.0 - sqrt ( 40.0 ) - 2.0 * sqrt ( 5.0 + sqrt ( 40.0 ) ) c4 = 5.0 + sqrt ( 10.0 ) - 3.0 * sqrt ( 5.0 + sqrt ( 40.0 ) ) c5 = 1.0 + sqrt ( 10.0 ) - sqrt ( 5.0 + sqrt ( 40.0 ) ) c0 = c0 / sqrt ( 512.0 ) c1 = c1 / sqrt ( 512.0 ) c2 = c2 / sqrt ( 512.0 ) c3 = c3 / sqrt ( 512.0 ) c4 = c4 / sqrt ( 512.0 ) c5 = c5 / sqrt ( 512.0 ) for i in range ( 0, n - 1, 2 ): a[i,i] = c0 a[i,i+1] = c1 a[i,i4_wrap(i+2,0,n-1)] = c2 a[i,i4_wrap(i+3,0,n-1)] = c3 a[i,i4_wrap(i+4,0,n-1)] = c4 a[i,i4_wrap(i+5,0,n-1)] = c5 a[i+1,i] = c5 a[i+1,i+1] = - c4 a[i+1,i4_wrap(i+2,0,n-1)] = c3 a[i+1,i4_wrap(i+3,0,n-1)] = - c2 a[i+1,i4_wrap(i+4,0,n-1)] = c1 a[i+1,i4_wrap(i+5,0,n-1)] = - c0 return a
def dif2cyclic ( n ): #*****************************************************************************80 # ## DIF2CYCLIC returns the cyclic second difference matrix. # # Example: # # N = 5 # # 2 -1 . . -1 # -1 2 -1 . . # . -1 2 -1 . # . . -1 2 -1 # -1 . . -1 2 # # Square Properties: # # A is symmetric: A' = A. # # Because A is symmetric, it is normal. # # Because A is normal, it is diagonalizable. # # A is persymmetric: A(I,J) = A(N+1-J,N+1-I). # # A is centrosymmetric: A(I,J) = A(N+1-I,N+1-J). # # A is a circulant: each row is shifted once to get the next row. # # A is (weakly) row diagonally dominant. # # A is (weakly) column diagonally dominant. # # A is singular. # # det ( A ) = 0. # # (1,1,...,1) is a null vector of A. # # A is cyclic tridiagonal. # # A is Toeplitz: constant along diagonals. # # A has constant row sum = 0. # # A has constant column sum = 0. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 22 January 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer N, the order of A. # # Output, real A(N,N), the matrix. # import numpy as np from i4_wrap import i4_wrap a = np.zeros ( [ n, n ] ) for i in range ( 0, n ): im1 = i4_wrap ( i - 1, 0, n - 1 ) a[i,im1] = -1.0 a[i,i] = 2.0 ip1 = i4_wrap ( i + 1, 0, n - 1 ) a[i,ip1] = -1.0 return a
def daub10 ( n ): #*****************************************************************************80 # ## DAUB10 returns the DAUB10 matrix. # # Discussion: # # The DAUB10 matrix is the Daubechies wavelet transformation matrix # with 10 coefficients. # # Properties: # # The family of matrices is nested as a function of N. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 14 January 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer N, the order of the matrix. # N must be at least 10 and a multiple of 2. # # Output, real A(N,N), the matrix. # import numpy as np from math import sqrt from i4_wrap import i4_wrap from sys import exit if ( n < 10 or ( n % 2 ) != 0 ): print '' print 'DAUB10 - Fatal error!' print ' N must be at least 10 and a multiple of 2.' exit ( 'DAUB10 - Fatal error!' ) a = np.zeros ( [ n, n ] ) c = np.array ( [ \ 0.1601023979741929, \ 0.6038292697971895, \ 0.7243085284377726, \ 0.1384281459013203, \ -0.2422948870663823, \ -0.0322448695846381, \ 0.0775714938400459, \ -0.0062414902127983, \ -0.0125807519990820, \ 0.0033357252854738 ] ) for i in range ( 0, n - 1, 2 ): a[i,i] = c[0] a[i,i+1] = c[1] a[i,i4_wrap(i+2,0,n-1)] = c[2] a[i,i4_wrap(i+3,0,n-1)] = c[3] a[i,i4_wrap(i+4,0,n-1)] = c[4] a[i,i4_wrap(i+5,0,n-1)] = c[5] a[i,i4_wrap(i+6,0,n-1)] = c[6] a[i,i4_wrap(i+7,0,n-1)] = c[7] a[i,i4_wrap(i+8,0,n-1)] = c[8] a[i,i4_wrap(i+9,0,n-1)] = c[9] a[i+1,i] = c[9] a[i+1,i+1] = - c[8] a[i+1,i4_wrap(i+2,0,n-1)] = c[7] a[i+1,i4_wrap(i+3,0,n-1)] = - c[6] a[i+1,i4_wrap(i+4,0,n-1)] = c[5] a[i+1,i4_wrap(i+5,0,n-1)] = - c[4] a[i+1,i4_wrap(i+6,0,n-1)] = c[3] a[i+1,i4_wrap(i+7,0,n-1)] = - c[2] a[i+1,i4_wrap(i+8,0,n-1)] = c[1] a[i+1,i4_wrap(i+9,0,n-1)] = - c[0] return a
def daub12 ( n ): #*****************************************************************************80 # ## DAUB12 returns the DAUB12 matrix. # # Discussion: # # The DAUB12 matrix is the Daubechies wavelet transformation matrix # with 12 coefficients. # # Properties: # # The family of matrices is nested as a function of N. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 16 January 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer N, the order of the matrix. # N must be at least 12 and a multiple of 2. # # Output, real A(N,N), the matrix. # import numpy as np from math import sqrt from i4_wrap import i4_wrap from sys import exit if ( n < 12 or ( n % 2 ) != 0 ): print '' print 'DAUB12 - Fatal error!' print ' N must be at least 12 and a multiple of 2.' exit ( 'DAUB12 - Fatal error!' ) a = np.zeros ( [ n, n ] ) c = np.array ( [ \ 0.1115407433501095, \ 0.4946238903984533, \ 0.7511339080210959, \ 0.3152503517091982, \ -0.2262646939654400, \ -0.1297668675672625, \ 0.0975016055873225, \ 0.0275228655303053, \ -0.0315820393174862, \ 0.0005538422011614, \ 0.0047772575109455, \ -0.0010773010853085 ] ) for i in range ( 0, n - 1, 2 ): a[i,i] = c[0] a[i,i+1] = c[1] a[i,i4_wrap(i+2,0,n-1)] = c[2] a[i,i4_wrap(i+3,0,n-1)] = c[3] a[i,i4_wrap(i+4,0,n-1)] = c[4] a[i,i4_wrap(i+5,0,n-1)] = c[5] a[i,i4_wrap(i+6,0,n-1)] = c[6] a[i,i4_wrap(i+7,0,n-1)] = c[7] a[i,i4_wrap(i+8,0,n-1)] = c[8] a[i,i4_wrap(i+9,0,n-1)] = c[9] a[i,i4_wrap(i+10,0,n-1)] = c[10] a[i,i4_wrap(i+11,0,n-1)] = c[11] a[i+1,i] = c[11] a[i+1,i+1] = - c[10] a[i+1,i4_wrap(i+2,0,n-1)] = c[9] a[i+1,i4_wrap(i+3,0,n-1)] = - c[8] a[i+1,i4_wrap(i+4,0,n-1)] = c[7] a[i+1,i4_wrap(i+5,0,n-1)] = - c[6] a[i+1,i4_wrap(i+6,0,n-1)] = c[5] a[i+1,i4_wrap(i+7,0,n-1)] = - c[4] a[i+1,i4_wrap(i+8,0,n-1)] = c[3] a[i+1,i4_wrap(i+9,0,n-1)] = - c[2] a[i+1,i4_wrap(i+10,0,n-1)] = c[1] a[i+1,i4_wrap(i+11,0,n-1)] = - c[0] return a
def dif1cyclic(n): #*****************************************************************************80 # ## DIF1CYCLIC returns the cyclic first difference matrix. # # Example: # # N = 5 # # 0 +1 . . -1 # -1 0 +1 . . # . -1 0 +1 . # . . -1 0 +1 # +1 . . -1 0 # # Square Properties: # # A is integral: int ( A ) = A. # # A is Toeplitz: constant along diagonals. # # A is antisymmetric: A' = -A. # # Because A is antisymmetric, it is normal. # # Because A is normal, it is diagonalizable. # # A has constant row sum = 0. # # A has constant column sum = 0. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 19 January 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer N, the number of rows and columns of A. # # Output, real A(N,N), the matrix. # import numpy as np from i4_wrap import i4_wrap a = np.zeros([n, n]) for i in range(0, n): im1 = i4_wrap(i - 1, 0, n - 1) a[i, im1] = -1.0 ip1 = i4_wrap(i + 1, 0, n - 1) a[i, ip1] = +1.0 return a
def daub8 ( n ): #*****************************************************************************80 # ## DAUB8 returns the DAUB8 matrix. # # Discussion: # # The DAUB8 matrix is the Daubechies wavelet transformation matrix # with 8 coefficients. # # Properties: # # The family of matrices is nested as a function of N. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 12 January 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer N, the order of the matrix. # N must be at least 8 and a multiple of 2. # # Output, real A(N,N), the matrix. # import numpy as np from math import sqrt from i4_wrap import i4_wrap from sys import exit if ( n < 8 or ( n % 2 ) != 0 ): print '' print 'DAUB8 - Fatal error!' print ' N must be at least 8 and a multiple of 2.' exit ( 'DAUB8 - Fatal error!' ) a = np.zeros ( [ n, n ] ) c0 = 0.2303778133088964 c1 = 0.7148465705529154 c2 = 0.6308807679298587 c3 = -0.0279837694168599 c4 = -0.1870348117190931 c5 = 0.0308413818355607 c6 = 0.0328830116668852 c7 = -0.0105974017850690 for i in range ( 0, n - 1, 2 ): a[i,i] = c0 a[i,i+1] = c1 a[i,i4_wrap(i+2,0,n-1)] = c2 a[i,i4_wrap(i+3,0,n-1)] = c3 a[i,i4_wrap(i+4,0,n-1)] = c4 a[i,i4_wrap(i+5,0,n-1)] = c5 a[i,i4_wrap(i+6,0,n-1)] = c6 a[i,i4_wrap(i+7,0,n-1)] = c7 a[i+1,i] = c7 a[i+1,i+1] = - c6 a[i+1,i4_wrap(i+2,0,n-1)] = c5 a[i+1,i4_wrap(i+3,0,n-1)] = - c4 a[i+1,i4_wrap(i+4,0,n-1)] = c3 a[i+1,i4_wrap(i+5,0,n-1)] = - c2 a[i+1,i4_wrap(i+6,0,n-1)] = c1 a[i+1,i4_wrap(i+7,0,n-1)] = - c0 return a
def dif1cyclic ( n ): #*****************************************************************************80 # ## DIF1CYCLIC returns the cyclic first difference matrix. # # Example: # # N = 5 # # 0 +1 . . -1 # -1 0 +1 . . # . -1 0 +1 . # . . -1 0 +1 # +1 . . -1 0 # # Square Properties: # # A is integral: int ( A ) = A. # # A is Toeplitz: constant along diagonals. # # A is antisymmetric: A' = -A. # # Because A is antisymmetric, it is normal. # # Because A is normal, it is diagonalizable. # # A has constant row sum = 0. # # A has constant column sum = 0. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 19 January 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer N, the number of rows and columns of A. # # Output, real A(N,N), the matrix. # import numpy as np from i4_wrap import i4_wrap a = np.zeros ( [ n, n ] ) for i in range ( 0, n ): im1 = i4_wrap ( i - 1, 0, n - 1 ) a[i,im1] = -1.0 ip1 = i4_wrap ( i + 1, 0, n - 1 ) a[i,ip1] = +1.0 return a