Returns the Laplace expansion along given row or column.
Matrix[[7,6], [3,9]].laplace_expansion(column: 1) # => 45 Matrix[[Vector[1, 0], Vector[0, 1]], [2, 3]].laplace_expansion(row: 0) # => Vector[3, -2]
Hadamard product
Matrix[[1,2], [3,4]].hadamard_product(Matrix[[1,2], [3,2]]) # => 1 4 # 9 8
Private. Use Matrix#determinant
Returns the determinant of the matrix, using Bareiss’ multistep integer-preserving gaussian elimination. It has the same computational cost order O(n^3) as standard Gaussian elimination. Intermediate results are fraction free and of lower complexity. A matrix of Integers will have thus intermediate results that are also Integers, with smaller bignums (if any), while a matrix of Float
will usually have intermediate results with better precision.
Explicit conversion to a Matrix
. Returns self
Returns an angle with another vector. Result is within the [0..Math::PI].
Vector[1,0].angle_with(Vector[0,1]) # => Math::PI / 2
Return a single-column matrix from this vector
mtch.values_at(index, ...) -> array
Uses each index to access the matching values, returning an array of the corresponding matches.
m = /(.)(.)(\d+)(\d)/.match("THX1138: The Movie") m.to_a #=> ["HX1138", "H", "X", "113", "8"] m.values_at(0, 2, -2) #=> ["HX1138", "X", "113"] m = /(?<a>\d+) *(?<op>[+\-*\/]) *(?<b>\d+)/.match("1 + 2") m.to_a #=> ["1 + 2", "1", "+", "2"] m.values_at(:a, :b, :op) #=> ["1", "2", "+"]
Returns the portion of the original string before the current match. Equivalent to the special variable $`
.
m = /(.)(.)(\d+)(\d)/.match("THX1138.") m.pre_match #=> "T"
Returns the portion of the original string after the current match. Equivalent to the special variable $'
.
m = /(.)(.)(\d+)(\d)/.match("THX1138: The Movie") m.post_match #=> ": The Movie"
This is similar to PrettyPrint::format
but the result has no breaks.
maxwidth
, newline
and genspace
are ignored.
The invocation of breakable
in the block doesn’t break a line and is treated as just an invocation of text
.
Returns the factorization of value
.
For an arbitrary integer:
p_1**e_1 * p_2**e_2 * ... * p_n**e_n,
prime_division
returns an array of pairs of integers:
[[p_1, e_1], [p_2, e_2], ..., [p_n, e_n]].
Each pair consists of a prime number – a prime factor – and a natural number – its exponent (multiplicity).
value
An arbitrary integer.
generator
Optional. A pseudo-prime generator. generator
.succ must return the next pseudo-prime number in ascending order. It must generate all prime numbers, but may also generate non-prime numbers, too.
ZeroDivisionError
when value
is zero.
Prime.prime_division(45) #=> [[3, 2], [5, 1]] 3**2 * 5 #=> 45
Load the given PStore
file. If read_only
is true, the unmarshalled Hash
will be returned. If read_only
is false, a 3-tuple will be returned: the unmarshalled Hash
, a checksum of the data, and the size of the data.
Returns the Ruby source filename and line number containing this proc or nil
if this proc was not defined in Ruby (i.e. native).