trace
Matrix trace.
📝Syntax
res = trace(x)
📥Input Arguments
Parameter Description
x a numeric value: scalar or matrix (double or single), dense or sparse
📤Output Arguments
Parameter Description
res a numeric value: a scalar
📄Description

trace(x) computes the trace of x, the sum of the elements along the main diagonal.

Sparse double, single, complex double, and complex single matrices are supported. The result keeps single precision for single inputs.

💡Examples
X = [1 0; 0 3];
Y = trace(X)
X = sparse(single([1 + 2i 0; 0 3]));
Y = trace(X)
🔗See Also
eig
🕔Version History
Version Description
1.0.0 initial version
2.0.0 added sparse single and complex single support
Edit this page on GitHub