def r8mat_is_inverse ( n, a, b ): #*****************************************************************************80 # ## R8MAT_IS_INVERSE measures the error in a matrix inverse. # # Discussion: # # An R8MAT is a matrix of real values. # # This routine returns the sum of the Frobenius norms of # A * B - I and B * A - I. # # 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. # # Input, real A(N,N), the matrix. # # Input, real B(M,N), the inverse matrix. # # Output, real VALUE, the Frobenius norm # of the difference matrices A * B - I and B * A - I. # from identity import identity from r8mat_mm import r8mat_mm from r8mat_sub import r8mat_sub from r8mat_norm_fro import r8mat_norm_fro ab = r8mat_mm ( n, n, n, a, b ) ba = r8mat_mm ( n, n, n, b, a ) id = identity ( n, n ) d1 = r8mat_sub ( n, n, ab, id ) d2 = r8mat_sub ( n, n, ba, id ) value = r8mat_norm_fro ( n, n, d1 ) \ + r8mat_norm_fro ( n, n, d2 ) return value
def r8mat_is_solution(m, n, k, a, x, b): #*****************************************************************************80 # ## R8MAT_IS_SOLUTION measures the error in a linear system solution. # # Discussion: # # An R8MAT is a matrix of real values. # # The system matrix A is an M x N matrix. # It is not required that A be invertible. # # The solution vector X is actually allowed to be an N x K matrix. # # The right hand side "vector" B is actually allowed to be an M x K matrix. # # This routine simply returns the Frobenius norm of the M x K matrix: # A * X - B. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 02 March 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer M, N, K, the order of the matrices. # # Input, real A(M,N), X(N,K), B(M,K), the matrices. # # Output, real VALUE, the Frobenius norm # of the difference matrix A * X - B, which would be exactly zero # if X was the "solution" of the linear system. # from r8mat_norm_fro import r8mat_norm_fro from r8mat_mm import r8mat_mm from r8mat_sub import r8mat_sub # # AX = A*X # ax = r8mat_mm(m, n, k, a, x) # # AXMB = AX-B. # axmb = r8mat_sub(m, k, ax, b) # # Value = ||AX-B|\ # value = r8mat_norm_fro(m, k, axmb) return value
def r8mat_is_solution ( m, n, k, a, x, b ): #*****************************************************************************80 # ## R8MAT_IS_SOLUTION measures the error in a linear system solution. # # Discussion: # # An R8MAT is a matrix of real values. # # The system matrix A is an M x N matrix. # It is not required that A be invertible. # # The solution vector X is actually allowed to be an N x K matrix. # # The right hand side "vector" B is actually allowed to be an M x K matrix. # # This routine simply returns the Frobenius norm of the M x K matrix: # A * X - B. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 02 March 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer M, N, K, the order of the matrices. # # Input, real A(M,N), X(N,K), B(M,K), the matrices. # # Output, real VALUE, the Frobenius norm # of the difference matrix A * X - B, which would be exactly zero # if X was the "solution" of the linear system. # from r8mat_norm_fro import r8mat_norm_fro from r8mat_mm import r8mat_mm from r8mat_sub import r8mat_sub # # AX = A*X # ax = r8mat_mm ( m, n, k, a, x ) # # AXMB = AX-B. # axmb = r8mat_sub ( m, k, ax, b ) # # Value = ||AX-B|\ # value = r8mat_norm_fro ( m, k, axmb ) return value
def r8mat_is_plu ( m, n, a, p, l, u ): #*****************************************************************************80 # ## R8MAT_IS_PLU measures the error in a PLU factorization. # # Discussion: # # An R8MAT is a matrix of real values. # # This routine computes the Frobenius norm of # # A - P * L * U # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 23 March 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer M, N, the order of the matrix. # # Input, real A(M,N), the matrix. # # Input, real P(M,M), L(M,M), U(M,N), the PLU factors. # # Output, real VALUE, the Frobenius norm # of the difference matrix A - P * L * U. # from r8mat_mm import r8mat_mm from r8mat_sub import r8mat_sub from r8mat_norm_fro import r8mat_norm_fro lu = r8mat_mm ( m, m, n, l, u ) plu = r8mat_mm ( m, m, n, p, lu ) d = r8mat_sub ( m, n, a, plu ) value = r8mat_norm_fro ( m, n, d ) return value