matrix.mult() - Pine Script Function
matrix.mult()
Section titled “matrix.mult()”Overview
Section titled “Overview”The function returns a new matrix resulting from the product between the matrices id1 and id2, or between an id1 matrix and an id2 scalar (a numerical value), or between an id1 matrix and an id2 vector (an array of values).
Syntax
Section titled “Syntax”matrix.mult(id1, id2) → array<int>Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| id1 | matrix | First matrix object. |
Returns
Section titled “Returns”A new matrix object containing the product of id2 and id1.
Examples
Section titled “Examples”Example 1
Section titled “Example 1”//@version=6indicator("`matrix.mult()` Example 3")// For efficiency, execute this code only once.if barstate.islastconfirmedhistory // Create a 2x3 matrix containing values `4`.var m1 = matrix.new<int>(2, 3, 4) // Create an array of three elements.var array<int> a = array.from(1, 1, 1) // Create a new matrix containing the product of the `m1` matrix and the `a` array.var m3 = matrix.mult(m1, a) // Display using a table.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, "x")table.cell(t, 2, 0, "Value:")table.cell(t, 2, 1, str.tostring(a, " "))table.cell(t, 3, 1, "=")table.cell(t, 4, 0, "Matrix 3:")table.cell(t, 4, 1, str.tostring(m3))