HyperMath

Multiplication

Multiplication

Previous topic Next topic No expanding text in this topic  

Multiplication

Previous topic Next topic JavaScript is required for expanding text JavaScript is required for the print function  

Multiplication is supported by the star operator, *, just like for scalars.

Multiplication between two vectors or matrices requires that the inner dimensions be equal.  That is A*B requires number of columns of A be equal to number of rows of B.  The exception is when one of them is a scalar.  The product is defined as follows:

The result is a vector or matrix.

> A = [1, 2, 3; 4, 5, 6]; print(A)

[Matrix] (2 x 3)

1        2        3

4        5        6

> B = [10; 20; 30]; print(B)

[Matrix] (3 x 1)

10

20

30

> print(A*B)

[Matrix] (2 x 1)

140

320

Multiplication for vector and matrices of complex data is supported.

x=[1+2i, 3+4i; 5, 7i]; print(x*x)

[Matrix] (2 x 2)

 

12 +    24i    -33 +    31i

 5 +    45i    -34 +    20i

Element wise multiplication is also supported using the dot notation (.*)

> A = [1, 2, 3]; B=[4, 5, 6]; C = A.*B; print(C)

[Matrix] (1 x 3)

4        10        18

> B = [10; 20; 30]; print(B.^2)

[Matrix] (3 x 1)

100

400

900

Scalars can also be raised to a vector or matrix. In such cases, a vector or matrix is created with each element in it being the scalar raised to the power of each element in the input vector or matrix.