Feature #2266 ยป matrix_complex.diff
| lib/matrix.rb | ||
|---|---|---|
|
# * <tt> #minor(*param) </tt>
|
||
|
#
|
||
|
# Properties of a matrix:
|
||
|
# * <tt> #real? </tt>
|
||
|
# * <tt> #regular? </tt>
|
||
|
# * <tt> #singular? </tt>
|
||
|
# * <tt> #square? </tt>
|
||
| ... | ... | |
|
# * <tt> #transpose </tt>
|
||
|
# * <tt> #t </tt>
|
||
|
#
|
||
|
# Complex arithmetic:
|
||
|
# * <tt> conj </tt>
|
||
|
# * <tt> conjugate </tt>
|
||
|
# * <tt> imag </tt>
|
||
|
# * <tt> imaginary </tt>
|
||
|
# * <tt> real </tt>
|
||
|
# * <tt> rect </tt>
|
||
|
# * <tt> rectangular </tt>
|
||
|
#
|
||
|
# Conversion to other data types:
|
||
|
# * <tt> #coerce(other) </tt>
|
||
|
# * <tt> #row_vectors </tt>
|
||
| ... | ... | |
|
#++
|
||
|
#
|
||
|
# Returns +true+ if all entries of the matrix are real.
|
||
|
#
|
||
|
def real?
|
||
|
@rows.all? do |row|
|
||
|
row.all? {|x| x.real? }
|
||
|
end
|
||
|
end
|
||
|
#
|
||
|
# Returns +true+ if this is a regular matrix.
|
||
|
#
|
||
|
def regular?
|
||
| ... | ... | |
|
alias t transpose
|
||
|
#--
|
||
|
# COMPLEX ARITHMETIC -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||
|
#++
|
||
|
#
|
||
|
# Returns the conjugate of the matrix.
|
||
|
# Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]]
|
||
|
# => 1+2i i 0
|
||
|
# 1 2 3
|
||
|
# Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]].conjugate
|
||
|
# => 1-2i -i 0
|
||
|
# 1 2 3
|
||
|
#
|
||
|
def conjugate
|
||
|
collect{|x| x.conjugate}
|
||
|
end
|
||
|
alias conj conjugate
|
||
|
#
|
||
|
# Returns the imaginary part of the matrix.
|
||
|
# Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]]
|
||
|
# => 1+2i i 0
|
||
|
# 1 2 3
|
||
|
# Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]].imaginary
|
||
|
# => 2i i 0
|
||
|
# 0 0 0
|
||
|
#
|
||
|
def imaginary
|
||
|
collect{|x| x.imaginary}
|
||
|
end
|
||
|
alias imag imaginary
|
||
|
#
|
||
|
# Returns the real part of the matrix.
|
||
|
# Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]]
|
||
|
# => 1+2i i 0
|
||
|
# 1 2 3
|
||
|
# Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]].real
|
||
|
# => 1 0 0
|
||
|
# 1 2 3
|
||
|
#
|
||
|
def real
|
||
|
collect{|x| x.real}
|
||
|
end
|
||
|
#
|
||
|
# Returns an array containing matrices corresponding to the real and imaginary
|
||
|
# parts of the matrix
|
||
|
#
|
||
|
# m.rect == [m.real, m.imag] # ==> true for all matrices m
|
||
|
#
|
||
|
def rect
|
||
|
matrix_r = []; matrix_i = []
|
||
|
@rows.each do |row|
|
||
|
row_r = []; row_i = []
|
||
|
row.each do |x|
|
||
|
r, i = x.rect
|
||
|
row_r << r; row_i << i
|
||
|
end
|
||
|
matrix_r << row_r; matrix_i << row_i
|
||
|
end
|
||
|
[
|
||
|
new_matrix(matrix_r, column_size),
|
||
|
new_matrix(matrix_i, column_size)
|
||
|
]
|
||
|
end
|
||
|
alias rectangular rect
|
||
|
#--
|
||
|
# CONVERTING -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||
|
#++
|
||