Skip to content
Algo Trade Analytics Docs

matrix.kron() - Pine Script Function

The function returns the Kronecker product for the id1 and id2 matrices.

matrix.kron(id1, id2) → matrix<float>
NameTypeDescription
id1matrix<int/float>First matrix object.

A new matrix containing the Kronecker product of id1 and id2.

//@version=6
indicator("`matrix.kron()` Example")// Display using a table.
if barstate.islastconfirmedhistory // Create two matrices with default values `1` and `2`.
var m1 = matrix.new<float>(2, 2, 1)
var m2 = matrix.new<float>(2, 2, 2) // Calculate the Kronecker product of the matrices.
var m3 = matrix.kron(m1, m2) // Display matrix elements.
var t = table.new(position.top_right, 5, 2, color.green)
table.cell(t, 0, 0, "Matrix 1:")
table.cell(t, 0, 1, str.tostring(m1))
table.cell(t, 1, 1, "⊗")
table.cell(t, 2, 0, "Matrix 2:")
table.cell(t, 2, 1, str.tostring(m2))
table.cell(t, 3, 1, "=")
table.cell(t, 4, 0, "Kronecker product:")
table.cell(t, 4, 1, str.tostring(m3))