GSL_Matrix class

Class methods

GSL_Matrix.new(argv)
GSL_Matrix.alloc(argv)

These methods create a GSL_Matrix object which contains matrix elements. One can initialize a matrix with arrays,

m = GSL_Matrix::new([1, 2, 3], [6, 5, 4], [7, 8, 1])
  -> a 3x3 matrix is created,
     1  2  3
     4  5  6
     7  8  9

With an array and rows&cols,

m = GSL_Matrix::new([1, 2, 3, 4, 5, 6, 7, 8, 9], 3, 3)

Methods

GSL_Matrix#set(argv)

This method sets elements of the matrix in various manners.

GSL_Matrix#get(i, j)

This method returns the (i,j)th element of the reciever matrix self.

GSL_Matrix#set_all(x)

This method sets all the elements of the reciever matrix to the value x.

GSL_Matrix#set_zero

This method sets all the elements of the matrix to zero.

GSL_Matrix#set_identity

This method sets the elements of the reciever matrix to the corresponding elements of the identity matrix, i.e. a unit diagonal with all off-diagonal elements zero. This applies to both square and rectangular matrices.

GSL_Matrix#fprintf(io, format)

This method writes the matrix elements line-by-line to the io object io using the format specifier format.

GSL_Matrix#fscanf(io)

This method reads formatted data from the io object io into the matrix.

Creating row and column vectors

GSL_Matrix#row(i)

This method returns a vector of the i-th row of the matrix.

GSL_Matrix#column(i)
GSL_Matrix#col(i)

These methods return a vector of the j-th column of the matrix.

GSL_Matrix#diagonal

This method returns a vector of the diagonal of the matrix.

GSL_Matrix#set_row(i, v)

This method copies the elements of the vector v into the i-th row of the matrix. The length of the vector must be the same as the length of the row.

GSL_Matrix#set_col(j, v)

This method copies the elements of the vector v into the j-th column of the matrix. The length of the vector must be the same as the length of the column.

GSL_Matrix#swap_rows!(i, j)

This method exchanges the i-th and j-th rows of the matrix in-place.

GSL_Matrix#swap_rows(i, j)

Same as GSL_Matrix#swap_rows!(i, j), but not modifies the reciever, and returns a new matrix.

GSL_Matrix#swap_columns!(i, j)
GSL_Matrix#swap_columns(i, j)

This method exchanges the i-th and j-th columns of the matrix.

GSL_Matrix#swap_rowcol!(i, j)
GSL_Matrix#swap_rowcol(i, j)

This method exchanges the i-th row and j-th column of the matrix. The matrix must be square for this operation to be possible.

GSL_Matrix#transpose!

This method returns a matrix of a transpose of the reciever matrix.

GSL_Matrix#transpose

This method replaces the reciever matrix by its transpose by copying the elements of the matrix in-place. The matrix must be square for this operation to be possible.

Matrix operations

GSL_Matrix#add(b)
GSL_Matrix#add!(b)

This method adds the elements of matrix b to the elements of the reciever matrix. The two matrices must have the same dimensions.

GSL_Matrix#sub!(b)
GSL_Matrix#sub(b)

This method subtracts the elements of matrix b from the elements of the reciever matrix. The two matrices must have the same dimensions.

GSL_Matrix#mul_elements!(b)
GSL_Matrix#mul_elements(b)

This method multiplies the elements of the reciever matrix by the elements of matrix b. The two matrices must have the same dimensions.

GSL_Matrix#div_elements!(b)
GSL_Matrix#div_elements(b)

This method divides the elements of the reciever matrix by the elements of matrix b. The two matrices must have the same dimensions.

GSL_Matrix#scale!(x)
GSL_Matrix#scale(x)

This method multiplies the elements of the reciever matrix by the constant factor x.

GSL_Matrix#add_constant!(a)
GSL_Matrix#add_constant(a)

This method adds the constant value x to the elements of the matrix.

Finding maximum and minimum elements of matrices

GSL_Matrix#max
GSL_Matrix#min

These methods return the max/min value in the reciever matrix.

GSL_Matrix#minmax

This method returns a two elements array [min, max], which contains the minimum and the maximum values in the reciever matrix.

GSL_Matrix#max_index
GSL_Matrix#min_index

These methods return the index of the max/min value in the reciever matrix.

GSL_Matrix#minmax_index

This method returns a two elements array [imin, imax], which contains the indices of the minimum and the maximum value in the reciever matrix.