Raises a square matrix to a whole-number power by repeated multiplication.
matrix.pow(m, 3) is m times m times m. A power of 0 gives the identity matrix.
Only a square matrix can be raised to a power, and a new matrix comes back. The matrix [[1, 1], [0, 1]] to the power 3 is [[1, 3], [0, 1]]: the top-right item grows by 1 with each multiplication.
Syntax
matrix.pow(id: matrix<int/float>, power: series int) -> matrix<float>
matrix.pow(id: matrix<int>, power: series int) -> matrix<int>
matrix.pow(power: series int) -> matrix<float>
matrix.pow(power: series int) -> matrix<int>Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | matrix<int/ | required | The square matrix multiplied by itself; it is left unchanged and the result is a new matrix. |
| power | series int | required | The whole-number exponent. 0 gives the identity matrix and a negative value raises the inverse, which needs a non-singular matrix. |
Returns
matrix<float>: A new float matrix equal to id multiplied by itself power times.matrix<int>: A new integer matrix equal to id multiplied by itself power times.matrix<float>: A new float matrix, the receiving matrix raised to power.matrix<int>: A new integer matrix, the receiving matrix raised to power.
Example
//@version=6
indicator("matrix.pow: two steps", overlay = false)
matrix<float> p = matrix.new<float>(2, 2, 0.5)
p2 = matrix.pow(p, 2)
plot(matrix.get(p2, 0, 0), "Two-step probability")See also
Runs on Sidechair