The TRACE function computes the trace of an n by n array.

This routine is written in the IDL language. Its source code can be found in the file trace.pro in the lib subdirectory of the IDL distribution.

Examples


; Define an array:
A = [[ 2.0,1.0, 1.0, 1.5], $
     [ 4.0, -6.0, 0.0, 0.0], $
     [-2.0, 7.0, 2.0, 2.5], $
     [ 1.0, 0.5, 0.0, 5.0]]
; Compute the trace of A:
result = TRACE(A)
;Print the result:
PRINT, 'TRACE(A) = ', result

IDL prints:

TRACE(A) =   3.00000

Syntax


Result = TRACE( A [, /DOUBLE] )

Return Value


Returns the sum of the values along the array diagonal.

Arguments


A

An n by n real or complex array.

Keywords


DOUBLE

Set this keyword to force the computation to be done in double-precision arithmetic.

Version History


5.0

Introduced

See Also


TOTAL