#NEWLINE# def cond( ctx , A , norm = None ) : #NEWLINE# #INDENT# "\n        Calculate the condition number of a matrix using a specified matrix norm.\n\n        The condition number estimates the sensitivity of a matrix to errors.\n        Example: small input errors for ill-conditioned coefficient matrices\n        alter the solution of the system dramatically.\n\n        For ill-conditioned matrices it's recommended to use qr_solve() instead\n        of lu_solve(). This does not help with input errors however, it just avoids\n        to add additional errors.\n\n        Definition:    cond(A) = ||A|| * ||A**-1||\n        " #NEWLINE# if ( norm is None ) : #NEWLINE# #INDENT# norm = ( lambda x : ctx . mnorm ( x , 1 ) ) #NEWLINE# #UNINDENT# return ( norm ( A ) * norm ( ctx . inverse ( A ) ) )