GSL::Matrix.new(n)
GSL::Matrix.new(size1, size2)
GSL::Matrix.new(array)
GSL::Matrix.new(arrays)
These methods create a GSL::Matrix
object.
ex1:
irb(main):002:0> m = Matrix.new([1, 2, 3], [4, 5, 6], [7, 8, 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 ] => #<GSL::Matrix:0x6e9644>
ex2: With an array and rows&cols,
m = Matrix.new([1, 2, 3, 4, 5, 6, 7, 8, 9], 3, 3)
ex3: With range objects,
irb(main):002:0> m = Matrix.new(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 ] => #<GSL::Matrix:0x6eb1ec> irb(main):004:0> m2 = Matrix.new(1..6, 2, 3) [ 1.000e+00 2.000e+00 3.000e+00 4.000e+00 5.000e+00 6.000e+00 ] => #<GSL::Matrix:0x6e51c0>
GSL::Matrix.eye(n, val = 1.0)
GSL::Matrix.diagonal(n, val = 1.0)
GSL::Matrix.identity(n)
GSL::Matrix.unit(n)
GSL::Matrix.I(n)
Matrix dimensions are limited within the range of Fixnum. For 32-bit CPU, the maximum of matrix dimension is 2^30 ~ 1e9.
GSL::Matrix#set(argv)
with two integers and a number,
m.set(1, 2, 3.2) -> the (1, 2) element is set to 3.2
with arrays,
m.set([6, 5, 6], [4, 5, 7], [8, 5, 21]) -> 6 5 6 4 5 7 8 5 21
with an array and sizes,
m.set([4, 5, 6, 8, 98, 6, 4, 3, 1], 3, 3) -> 4 5 6 8 98 6 4 3 1
GSL::Matrix#get(i, j)
GSL::Matrix#set_all(x)
GSL::Matrix#set_zero
GSL::Matrix#set_identity
GSL::Matrix#fwrite(io)
GSL::Matrix#fwrite(filename)
GSL::Matrix#fread(io)
GSL::Matrix#fread(filename)
GSL::Matrix#fprintf(io, format = "%e")
GSL::Matrix#fprintf(filename, format = "%e")
GSL::Matrix#fscanf(io)
GSL::Matrix#fscanf(filename)
The GSL::Matrix::View
class is defined to be used as "references" to
the matrices. The Matrix::View
class is a subclass of the class Matrix
,
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 vector, i.e. any changes
in the elements of the View
object affect to the original.
GSL::Matrix#submatrix(k1, k2, n1, n2)
GSL::Matirx::View
object, a submatrix of the matrix
self. The upper-left element of the submatrix is the element (k1,k2)
of the original matrix. The submatrix has n1 rows and n2 columns. GSL::Vectir#matrix_view(n1, n2)
Matrix::View
object from the vector self.
ex:
v2 = Vector.new([1, 2, 3, 4, 5, 6, 7, 8, 9]) mview = v2.matrix_view(3, 3) p mview.class <----- GSL::Matrix::View mview.print <----- [ 1 2 3 4 5 6 7 8 9 ] mview.set(2, 1, 99.9) mview.print <----- [ 1 2 3 4 5 6 7 99.9 9 ] v2.print <----- [ 1 2 3 4 5 6 7 99.9 9 ]
GSL::Matrix#row(i)
GSL::Matrix#column(i)
GSL::Matrix#col(i)
GSL::Matrix#diagonal
GSL::Matrix#subdiagonal(k)
GSL::Matrix#superdiagonal(k)
GSL::Matrix#each_row
GSL::Matrix#each_col
GSL::Matrix#clone
GSL::Matrix.memcpy(dest, src)
GSL::Matrix.swap(dest, src)
GSL::Matrix#get_row(i, v)
GSL::Matrix#get_col(j, v)
GSL::Matrix#set_row(i, v)
GSL::Matrix#set_col(j, v)
GSL::Matrix#swap_rows(i, j)
GSL::Matrix#swap_columns(i, j)
GSL::Matrix#swap_rowcol(i, j)
GSL::Matrix#transpose!
GSL::Matrix#transpose_memcpy
GSL::Matrix#transpose
GSL::Matrix#add(b)
GSL::Matrix#+(b)
GSL::Matrix#add!(b)
GSL::Matrix#+=(b)
This method adds the elements of matrix b to the elements of the matrix. The two matrices must have the same dimensions.
If b is a scalar, these methods add it to all the elements
of the matrix self (equivalent to the method add_constant
).
GSL::Matrix#sub(b)
GSL::Matrix#-(b)
GSL::Matrix#sub!(b)
GSL::Matrix#-=(b)
GSL::Matrix#mul_elements(b)
GSL::Matrix#*(b)
GSL::Matrix#mul_elements!(b)
GSL::Matrix#*=(b)
GSL::Matrix#**(b)
GSL::Matrix#div_elements(b)
GSL::Matrix#/(b)
GSL::Matrix#div_elements!(b)
GSL::Matrix#/=(b)
GSL::Matrix#scale!(x)
GSL::Matrix#scale(x)
GSL::Matrix#add_constant!(x)
GSL::Matrix#add_constant(x)
GSL::Matrix#max
GSL::Matrix#min
GSL::Matrix#minmax
GSL::Matrix#max_index
GSL::Matrix#min_index
GSL::Matrix#minmax_index
GSL::Matrix#isnull
GSL::Matrix#isnull?
true
if all the elements of the matrix self are zero,
and false
otherwise.GSL:Matrix#trace
GSL::Matrix#to_na
GSL::Vector.na_to_gm(na)
GSL::Matrix.to_gm(na)
GSL::Vector::View
object is created from the NArray object na.
The data of na are
not copied, thus any modifications to the View object affect on the original
NArray object na. The View object can be used as a reference to the NMatrix
object.