tracem

Purpose

Returns the trace of a matrix or multi-dimensional array.

Format

t = tracem(A)
Parameters:

A (NxM matrix, or multidimensional array.) – Data.

Returns:

t (Scalar, or multidimensional array.) – The trace of the matrix.

Examples

A = { 1 2,
      3 4 };

// Compute the trace of the matrix
t = tracem(A);

After the code above:

t = 5
// Create a 2x3x3 array
A = areshape(seqa(1,1,18), 2|3|3);
print A;
Plane [1,.,.]

     1              2              3
     4              5              6
     7              8              9

Plane [2,.,.]

    10             11             12
    13             14             15
    16             17             18
t = tracem(A);
print t;
Plane [1,.,.]
    15

Plane [2,.,.]
    42

See also

Functions norm(), powerm()