Sidechair

matrix.is_symmetric()

Browse the reference

Returns true when a matrix equals its own transpose.

Try it in the editor

A symmetric matrix mirrors itself across the main diagonal, so item (i, j) equals item (j, i): [[1, 4], [4, 2]] passes and [[1, 4], [5, 2]] fails.

Covariance and correlation matrices are symmetric by construction. A matrix that is not square cannot be symmetric.

Syntax

Pine Script
matrix.is_symmetric(id: matrix<int/float>) -> series bool
matrix.is_symmetric() -> series bool

Arguments

NameTypeDefaultDescription
idmatrix<int/float>requiredThe matrix compared with its own transpose; every item must equal its mirror across the main diagonal.

Returns

  • series bool: true when the matrix equals its transpose, otherwise false.
  • series bool: true when the receiving matrix is symmetric, otherwise false.

Example

Pine ScriptCorrelation matrix checkOpen in editor
//@version=6
indicator("matrix.is_symmetric: correlation", overlay = false)
matrix<float> c = matrix.new<float>(2, 2, 1.0)
matrix.set(c, 0, 1, 0.4)
matrix.set(c, 1, 0, 0.4)
plot(matrix.is_symmetric(c) ? 1 : 0, "Symmetric")

See also

Runs on Sidechair