matrix define A = (1,2,3 \ 4,5,6)
// Creates a matrix 2X3 matrix A containing the values 1,2,3 in row 1 and the values 4,5,6 in row 2.
mat B = (1,2,3 \ 4,5,6) // Identical to matrix A (writing "define" is optional)
mat C = J(3,2,1)
// Creates a 3X2 matrix containing only the value 1 in all cells. J(rows,columns,content in each cell)
matrix list A // Display content of matrix A.
matrix list B
matrix list C
mat C[3,1] = 10 // Change C3,1 (i.e. value in row 3, column 1 of matrix C) to 10.
matrix list C
mat D1 = (el(C,1,1), el(C,3,1))
// Creates 1X2 matrix with value C11 in first column and value C31 in second column. el stands for element
mat D2 = (C[1,1], C[3,1]) // Same as above.
matrix list D1
matrix list D2
* Calculations with matrices
mat E = A' // Transpose of matrix A.
matrix list E
mat F = A+B // Sum of matrices A and B.
matrix list F
mat G = A*B' // Product of matrix A and transpose of B. - Make sure that dimensions match.
matrix list G
mat H = A * a // Product of matrix A and scalar a.
matrix list H
mat J = (1,2 \ 2,5)
matrix list J
mat K = inv(J) // Calculates inverse of matrix J.
matrix list K
mat I = invsym(J) // Same as above but executes faster for large matrices (only works if matrix is symmetric).
matrix list I