; $Id: cond.pro,v 1.1 1993/04/02 19:43:31 idl Exp $ FUNCTION COND, A ;+ ;NAME: ; COND ; ;PURPOSE: ; Computes the condition number of the ; input NxN MATRIX: A. ; ;CATEGORY: ; Numerical Analysis ; ;CALLING SEQUENCE: ; cond_num=COND(A) ; ;INPUTS: ; A: The NxN MATRIX whose condition is ; in question. ; ;OPTIONAL INPUT PARAMETERS: ; None ; ;OUTPUTS: ; Returns the condition number (scalar_valued) ; corresponding to the NxN MATRIX: A ; ;SIDE EFFECTS: ; Floating point error will result if matrix A ; is singular or near singular. ; ;RESTRICTIONS: ; Input matrix A must be of dimension NxN (square). ; ;PROCEDURE: ; This function returns the condition number ; by explicitly computing the formula: ; cond_number=norm(A)*norm(A_inverse). A ; matrix whose condition number is found ; to be large, relative to its individual ; entries, will give questionable results ; when used in the solution of the ; simultaneous linear equations Ax=b. ; ;MODIFICATION HISTORY: ; GGS, April, 1992 ;- ; ; find the maximum absolute value of A. scale=max(abs(A)) ; scale A by its maximum absolute value. A_scaled=A/scale ; compute the norm of the scaled matrix. norm1=norm(A_scaled) ; compute the inverse of the scaled matrix. A_inv_scaled=invert(A_scaled) ; compute the norm of the scaled inverse. norm2=norm(A_inv_scaled) ; computue the condition number. cond_num=norm1*norm2 return,cond_num end