HyperMath

Concatenation - Vector and Matrix Data

Concatenation - Vector and Matrix Data

Previous topic Next topic No expanding text in this topic  

Concatenation - Vector and Matrix Data

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

You can build vectors and matrices from existing ones.

> x = [1, 2, 3]; print(x)

[Matrix] (1 x 3)

1 2 3

> y = [x, 4, 5, 6]; print(y) // append more to create a new vector

[Matrix] (1 x 6)

1        2        3        4        5        6

The dimensions have to be compatible. y = [x, 4; 5; 6] would not work because you cannot concatenate a row vector with a column vector.  This can be used to grow a vector if the result is assigned to the vector itself, like x = [x, 4, 5, 6].

Similarly a matrix can be built from existing vectors

> x = [1, 2, 3]; y = [4, 5, 6];

> z = [x; y]; print(z)

[Matrix] (2 x 3)

1 2 3

4 5 6

Or, from other matrices.

> x = [1, 2; 3, 4]; y = [5, 6; 7, 8];

> z = [x, y]; print(z)        // horizontal concatenation

[Matrix] (2 x 4)

1        2        5        6

3        4        7        8

 

> z = [x; y]; print(z) // vertical concatenation

 [Matrix] (4 x 2)

12

3        4

5        6

7        8

Any combination of vectors and matrices will work as long as the dimensions match.  For matrix concatenation, the number of rows must be equal for horizontal concatenation and the number of columns must be equal for vertical concatenation.