Power Operator, Elementwise:   ##

matrix1 ## matrix2 ;
matrix ## scalar ;
matrix ## vector ;

The elementwise power operator (##) creates a new matrix with elements that are the elements of matrix1 raised to the power of the corresponding element of matrix2. If any value in matrix1 is negative, the corresponding element in matrix2 must be an integer.

The elementwise power operator enables either operand to be a scalar or a row or column vector.

  • If either operand is scalar, the operation applies the power operator to each element and the scalar value.

  • When you use the matrix / vector form, each row or column of the matrix is raised to a power given by a corresponding element of the vector.

When an element of either matrix contains a missing value, the corresponding element of the result is also a missing value.

For example, the following statements raise each element of a matrix to a power, as shown in Figure 23.20:

a = {1 2 3};
b = a##3;
c = a##0.5;
print b, c;

Figure 23.20 Result of Raising Each Element to a Power
b
1 8 27

c
1 1.4142136 1.7320508