Esempio n. 1
0
def symm_random_eigen_right ( n, d, key ):

#*****************************************************************************80
#
## SYMM_RANDOM_EIGEN_RIGHT returns right eigenvectors for the SYMM_RANDOM matrix.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    11 March 2015
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, integer N, the order of A.
#
#    Input, real D(N), the desired eigenvalues for the matrix.
#
#    Input, integer KEY, a positive integer that selects the data.
#
#    Output, real V(N,N), the vectors.
#
  from orth_random import orth_random
#
#  Get a random orthogonal matrix Q.
#
  x = orth_random ( n, key )

  return x
Esempio n. 2
0
def symm_random ( n, d, key ):

#*****************************************************************************80
#
## SYMM_RANDOM returns the SYMM_RANDOM matrix.
#
#  Properties:
#
#    A is symmetric: A' = A.
#
#    The eigenvalues of A will be real.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    11 March 2015
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, integer N, the order of A.
#
#    Input, real D(N), the desired eigenvalues for the matrix.
#
#    Input, integer KEY, a positive integer that selects the data.
#
#    Output, real A(N,N), the matrix.
#
  import numpy as np
  from orth_random import orth_random
#
#  Get a random orthogonal matrix Q.
#
  q = orth_random ( n, key )
#
#  Set A = Q * Lambda * Q'.
#
  a = np.zeros ( ( n, n ) )

  for j in range ( 0, n ):
    for i in range ( 0, n ):
      for k in range ( 0, n ):
        a[i,j] = a[i,j] + q[i,k] * d[k] * q[j,k]

  return a
Esempio n. 3
0
def idem_random_eigen_right ( n, rank, key ):

#*****************************************************************************80
#
## IDEM_RANDOM_EIGEN_RIGHT returns the right eigenvectors of the IDEM_RANDOM matrix.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    17 March 2015
#
#  Author:
#
#    John Burkardt
#
#  Reference:
#
#    Alston Householder, John Carpenter,
#    The singular values of involutory and of idempotent matrices,
#    Numerische Mathematik,
#    Volume 5, 1963, pages 234-237.
#
#  Parameters:
#
#    Input, integer N, the order of the matrix.
#
#    Input, integer RANK, the rank of A.
#    0 <= RANK <= N.
#
#    Input, integer KEY, a positive value that selects the data.
#
#    Output, real X(N,N), the matrix.
#
  import numpy as np
  from orth_random import orth_random

  x = orth_random ( n, key )

  x = np.transpose ( x )

  return x
Esempio n. 4
0
def pds_random_eigen_right ( n, key ):

#*****************************************************************************80
#
## PDS_RANDOM_EIGEN_RIGHT returns the right eigenvectors of the PDS_RANDOM matrix.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    20 March 2015
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, integer N, the order of A.
#
#    Input, integer KEY, a positive value that selects the data.
#
#    Output, real Q(N,N), the matrix.
#
  from orth_random import orth_random
  from r8vec_uniform_01 import r8vec_uniform_01
#
#  Get a random set of eigenvalues.
#
  seed = key
  lam, seed = r8vec_uniform_01 ( n, seed )
#
#  Get a random orthogonal matrix Q.
#
  q = orth_random ( n, key )

  return q
Esempio n. 5
0
def pds_random_eigen_right(n, key):

    #*****************************************************************************80
    #
    ## PDS_RANDOM_EIGEN_RIGHT returns the right eigenvectors of the PDS_RANDOM matrix.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    20 March 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Parameters:
    #
    #    Input, integer N, the order of A.
    #
    #    Input, integer KEY, a positive value that selects the data.
    #
    #    Output, real Q(N,N), the matrix.
    #
    from orth_random import orth_random
    from r8vec_uniform_01 import r8vec_uniform_01
    #
    #  Get a random set of eigenvalues.
    #
    seed = key
    lam, seed = r8vec_uniform_01(n, seed)
    #
    #  Get a random orthogonal matrix Q.
    #
    q = orth_random(n, key)

    return q
Esempio n. 6
0
def pds_random ( n, key ):

#*****************************************************************************80
#
## PDS_RANDOM returns a random positive definite symmetric matrix.
#
#  Discussion:
#
#    The matrix returned will have eigenvalues in the range [0,1].
#
#  Properties:
#
#    A is symmetric: A' = A.
#
#    A is positive definite: 0 < x'*A*x for nonzero x.
#
#    The eigenvalues of A will be real.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    20 March 2015
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, integer N, the order of A.
#
#    Input, integer KEY, a positive value that selects the data.
#
#    Output, real A(N,N), the matrix.
#
  import numpy as np
  from orth_random import orth_random
  from r8vec_uniform_01 import r8vec_uniform_01
#
#  Get a random set of eigenvalues.
#
  seed = key
  lam, seed = r8vec_uniform_01 ( n, seed )
#
#  Get a random orthogonal matrix Q.
#
  q = orth_random ( n, key )
#
#  Set A = Q * Lambda * Q'.
#
  a = np.zeros ( ( n, n ) )

  for i in range ( 0, n ):
    for j in range ( 0, n ):
      for k in range ( 0, n ):
        a[i,j] = a[i,j] + q[i,k] * lam[k] * q[j,k]

  return a
Esempio n. 7
0
def pds_random(n, key):

    #*****************************************************************************80
    #
    ## PDS_RANDOM returns a random positive definite symmetric matrix.
    #
    #  Discussion:
    #
    #    The matrix returned will have eigenvalues in the range [0,1].
    #
    #  Properties:
    #
    #    A is symmetric: A' = A.
    #
    #    A is positive definite: 0 < x'*A*x for nonzero x.
    #
    #    The eigenvalues of A will be real.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    20 March 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Parameters:
    #
    #    Input, integer N, the order of A.
    #
    #    Input, integer KEY, a positive value that selects the data.
    #
    #    Output, real A(N,N), the matrix.
    #
    import numpy as np
    from orth_random import orth_random
    from r8vec_uniform_01 import r8vec_uniform_01
    #
    #  Get a random set of eigenvalues.
    #
    seed = key
    lam, seed = r8vec_uniform_01(n, seed)
    #
    #  Get a random orthogonal matrix Q.
    #
    q = orth_random(n, key)
    #
    #  Set A = Q * Lambda * Q'.
    #
    a = np.zeros((n, n))

    for i in range(0, n):
        for j in range(0, n):
            for k in range(0, n):
                a[i, j] = a[i, j] + q[i, k] * lam[k] * q[j, k]

    return a
Esempio n. 8
0
def idem_random ( n, rank, key ):

#*****************************************************************************80
#
## IDEM_RANDOM returns a random idempotent matrix of rank K.
#
#  Properties:
#
#    A is idempotent: A * A = A
#
#    If A is invertible, then A must be the identity matrix.
#    In other words, unless A is the identity matrix, it is singular.
#
#    I - A is also idempotent.
#
#    All eigenvalues of A are either 0 or 1.
#
#    rank(A) = trace(A)
#
#    A is a projector matrix.
#
#    The matrix I - 2A is involutory, that is ( I - 2A ) * ( I - 2A ) = I.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    14 February 2015
#
#  Author:
#
#    John Burkardt
#
#  Reference:
#
#    Alston Householder, John Carpenter,
#    The singular values of involutory and of idempotent matrices,
#    Numerische Mathematik,
#    Volume 5, 1963, pages 234-237.
#
#  Parameters:
#
#    Input, integer N, the order of A.
#
#    Input, integer RANK, the rank of A.
#    0 <= RANK <= N.
#
#    Input, integer KEY, a positive value that selects the data.
#
#    Output, real A(N,N), the matrix.
#
  import numpy as np
  from orth_random import orth_random
  from sys import exit

  if ( rank < 0 or n < rank ):
    print ''
    print 'IDEM_RANDOM - Fatal error!'
    print '  RANK must be between 0 and N.'
    print '  Input value = %d' % ( rank )
    exit ( 'IDEM_RANDOM - Fatal error!' )
#
#  Get a random orthogonal matrix Q.
#
  q = orth_random ( n, key )
#
#  Compute Q' * D * Q, where D is the diagonal eigenvalue matrix
#  of RANK 1's followed by N-RANK 0's.
#
  a = np.zeros ( ( n, n ) )

  for i in range ( 0, n ):
    for j in range ( 0, n ):
      t = 0.0
      for k in range ( 0, rank ):
        t = t + q[k,i] * q[k,j]
      a[i,j] =  t

  return a