Language Reference


Power Operator, Matrix:   **

  • matrix ** scalar;

The matrix power operator (**) creates a new matrix that is matrix multiplied by itself scalar times. The matrix argument must be square; scalar must be an integer greater than or equal to $-1$. If the scalar is not an integer, it is truncated to an integer.

For example, the following statements compute a matrix that is the result of multiplying a matrix by itself. The result is shown in Figure 24.23.

 a = {1 2,
      1 1};
 c = a**2;
print c;

Figure 24.23: Result of Raising a Matrix to a Power

c
3 4
2 3



Note that the expression a**(-1) is shorthand for matrix inversion, as shown by the following statements:

 inv = a**(-1);              /* shorthand for matrix inversion */
 ident = inv * a;
 print inv, ident;

Figure 24.24: Matrix Inversion by Using the Power Operator

inv
-1 2
1 -1

ident
1 0
0 1



The matrix power operator does not support missing values.

Raising a matrix to a large power can cause numerical precision problems. If the matrix is symmetric, it is preferable to operate on its eigenvalues (see the EIGEN call ) rather than to use the matrix power operator directly on the matrix, as shown in the following example:

 b = {2 1,
      1 1};
 call eigen(lambda, E, b);   /* recall that b = E*diag(lambda)*E` */
 power = 20;
 d = lambda##power;
 a20 = E*diag(d)*E`;         /* a**20 since E`*E = Identity */
 print a20;

Figure 24.25: Matrix Powers by Using Eigenvalues

a20
165580141 102334155
102334155 63245986