зеркало из https://github.com/github/ruby.git
* lib/matrix.rb: New Complex instance methods:
conjugate, conj, imaginary, imag, real, real?, rectangular, rect [ruby-core:26285] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27159 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
277cb36b21
Коммит
729941da39
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
|||
Fri Apr 2 02:56:56 2010 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
|
||||
|
||||
* lib/matrix.rb: : New instance methods:
|
||||
empty? [ruby-core:26284], each, each_with_index [ruby-core:28400],
|
||||
conjugate, conj, imaginary, imag, real, real?, rectangular, rect
|
||||
[ruby-core:26285]
|
||||
|
||||
Removed compare_by*, inspect_org, cf [ruby-core:26268]
|
||||
|
||||
Matrix.empty: raise on negative sizes
|
||||
|
||||
Matrix.determinant: raise on rectangular matrices [ruby-core:28271]
|
||||
|
||||
Thu Apr 1 17:17:00 2010 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* enc/trans/iso2022.trans: CP50221 supports 8bit JIS.
|
||||
|
|
|
@ -70,6 +70,7 @@ end
|
|||
# * <tt> #minor(*param) </tt>
|
||||
#
|
||||
# Properties of a matrix:
|
||||
# * <tt> #real? </tt>
|
||||
# * <tt> #regular? </tt>
|
||||
# * <tt> #singular? </tt>
|
||||
# * <tt> #square? </tt>
|
||||
|
@ -92,6 +93,15 @@ end
|
|||
# * <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>
|
||||
|
@ -434,6 +444,13 @@ class Matrix
|
|||
column_size == 0 || row_size == 0
|
||||
end
|
||||
|
||||
#
|
||||
# Returns +true+ if all entries of the matrix are real.
|
||||
#
|
||||
def real?
|
||||
all?(&:real?)
|
||||
end
|
||||
|
||||
#
|
||||
# Returns +true+ if this is a regular matrix.
|
||||
#
|
||||
|
@ -897,6 +914,62 @@ class Matrix
|
|||
end
|
||||
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(&: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(&: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(&: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
|
||||
[real, imag]
|
||||
end
|
||||
alias rectangular rect
|
||||
|
||||
#--
|
||||
# CONVERTING -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
#++
|
||||
|
|
Загрузка…
Ссылка в новой задаче