Matrices and arrays¶
The Julia programming language provides a wide range of possibilities for creating and editing matrices. In this example some of them will be considered.
To create a matrix consisting of several rows, divide the matrix elements by semicolon:
a = [1 3 5; 2 4 6; 7 8 10]
Julia allows you to process all values in a matrix with a single arithmetic operator or function by specifying a dot in front of it, which means that the operator is applied element by element:
a .+ 10
Element-by-element degree expansion:
a .^ 3
You can also apply functions to matrices:
sin(a)
The transpose of a matrix can be done in two ways, the first is by specifying an apostrophe:
a'
The second way is by using the transpose function:
transpose(a)
The concatenation of matrices is done by specifying them in square brackets, with or without semicolon, which means vertical and horizontal addition, respectively:
A = [a; a]
Concatenation of matrices horizontally:
A = [a a]
You can also use complex numbers as array elements by defining them through im:
c = [3+4im 4+3im; -im 10im]