Matrices

Contents:

  1. Class methods

  2. Instance methods

    1. Accessing matrix elements

    2. Initializing matrix elements

    3. IO

    4. Matrix views

    5. Creating row and column views

    6. Iterators

    7. Copying matrices

    8. Copying rows and columns

    9. Exchanging rows and columns

    10. Matrix operations

    11. Finding maximum and minimum elements of matrices

    12. Matrix properties

  3. NArray

  4. Special matrices

Class methods


  1. From arrays

    >> m = GSL::Matrix[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
    => GSL::Matrix
    [ 1.000e+00 2.000e+00 3.000e+00
      4.000e+00 5.000e+00 6.000e+00
      7.000e+00 8.000e+00 9.000e+00 ]
  2. With an array and rows&cols,

    m = GSL::Matrix.alloc([1, 2, 3, 4, 5, 6, 7, 8, 9], 3, 3)
    
  3. With Range objects,

    >> m = GSL::Matrix.alloc(1..3, 4..6, 7..9)
    [ 1.000e+00 2.000e+00 3.000e+00
      4.000e+00 5.000e+00 6.000e+00
      7.000e+00 8.000e+00 9.000e+00 ]
    >> m2 = GSL::Matrix[1..6, 2, 3]
    [ 1.000e+00 2.000e+00 3.000e+00
      4.000e+00 5.000e+00 6.000e+00 ]






NOTE:

Matrix dimensions are limited within the range of Fixnum. For 32-bit CPU, the maximum of matrix dimension is 2^30 ~ 1e9.

Instance Methods

Accessing matrix elements







Initializing matrix elements




IO


Matrix views

The GSL::Matrix::View class is defined to be used as “references” to matrices. The Matrix::View class is a subclass of Matrix, and an instance of the View class created by slicing a Matrix object can be used same as the original matrix. The View object shares the data with the original matrix, i.e. any changes in the elements of the View object affect to the original.

The primary means of generating Matrix::View objects is with GSL::Matrix#submatrix (or its alias GSL::Matrix#view). Many forms are supported and they are documented here individually. All forms return a Matrix::View unless otherwise documented. In the list below, the parameter name indicates the type of the parameter: i, row, col, len, len1, and len2 are Fixnums; rows and cols are Ranges.


















Creating row and column views









Iterators




Copying matrices



Copying rows and columns





Exchanging rows and columns















Matrix operations










Finding maximum and minimum elements of matrices





Matrix properties













NArray




Special matrices







prev next

Reference index top