Name

Matrix — Matrix class

Required Library

require ‘matrix’

Class Methods

Matrix::[row...]

Creates a matrix where row indicates each row of the matrix.

Matrix[[11, 12], [21, 22]]
Matrix::identity(n)
Matrix::unit(n)
Matrix::I(n)

Creates an n-by-n unit matrix.

Matrix::columns(columns)

Creates a new matrix using columns as sets of column vectors.

Matrix::columns([[11, 12], [21, 22]]) # => Matrix[[11, 21], [12, 22]]
Matrix::column_vector(column)

Creates a 1-by-n matrix such that column vector is column.

Matrix::diagonal(value...)

Creates a matrix where diagonal components are specified by value.

Matrix.diagonal(11, 22, 33)  # => Matrix[[11, 0, 0], 
      [0, 22, 0], [0, 0, 33]]
Matrix::rows(rows[, copy=true])

Creates a matrix where rows is an array of arrays that indicates rows of the matrix. If the optional argument copy is false, use the given arrays as the internal structure of the matrix without copying.

Matrix::rows([[11, 12], [21, 22]])
Matrix::row_vector(row)

Creates an 1-by-n matrix such that the row vector is row.

Matrix::scalar(n, value)

Creates an n-by-n diagonal matrix such that the diagonal components are given by value.

Matrix::scalar(3,81)    # => Matrix[[81,0,0],[0,81,0],[0,0,81]]
p ParseDate::parsedate("Fri Aug  3 17:16:57 JST 2001")
# => [2001, 8, 3, 17, 16, 57, "JST", 5]
p ParseDate::parsedate("1993-02-24")
# => [1993, 2, 24, nil, nil, nil, nil, nil]
Matrix::zero(n)

Creates an n-by-n zero matrix.

Instance Methods

m[i,j]

Returns (i,j) component.

m * mtx

Multiplication.

m + mtx

Addition.

m- mtx

Subtraction. ...

Get Ruby in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.