Sidechair

matrix.det()

Browse the reference

Returns the determinant of a square matrix.

Try it in the editor

The determinant is one number that tells how the matrix scales area or volume and whether it flips orientation. For a 2 by 2 matrix [[a, b], [c, d]] it is a times d minus b times c, so [[3, 1], [2, 4]] gives 10.

A determinant of 0 marks a singular matrix with no inverse, so test it before calling matrix.inv(). The input must be square. After floating-point work the value can land a hair away from 0, so compare against a small tolerance.

Syntax

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

Arguments

NameTypeDefaultDescription
idmatrix<int/float> or matrix<int>requiredThe square matrix whose determinant is wanted; a matrix that is not square is rejected.

Returns

  • series float: The determinant as a float, for example 10.0 for [[3.0, 1.0], [2.0, 4.0]].
  • series int: The determinant as a whole number, because the matrix holds ints.
  • series float: The determinant of the receiving matrix as a float.
  • series int: The determinant of the receiving matrix as a whole number.

Example

Pine ScriptCheck invertibilityOpen in editor
//@version=6
indicator("matrix.det: invertible?", overlay = false)
matrix<float> m = matrix.new<float>(2, 2, 0.0)
matrix.set(m, 0, 0, 4.0)
matrix.set(m, 1, 1, 2.0)
plot(matrix.det(m), "Determinant")

See also

Runs on Sidechair