mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/matrix.rb: Matrix.zero can build rectangular matrices.
Vector#r should be called #magnitude git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32280 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
de97e946f0
commit
54bbc098fa
3 changed files with 13 additions and 4 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Wed Jun 29 10:13:12 2011 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
|
||||||
|
|
||||||
|
* lib/matrix.rb: Matrix.zero can build rectangular matrices.
|
||||||
|
Vector#r should be called #magnitude
|
||||||
|
|
||||||
Wed Jun 29 10:11:08 2011 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
|
Wed Jun 29 10:11:08 2011 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
|
||||||
|
|
||||||
* lib/matrix.rb: Add Matrix#diagonal?, hermitian?, normal?,
|
* lib/matrix.rb: Add Matrix#diagonal?, hermitian?, normal?,
|
||||||
|
|
2
NEWS
2
NEWS
|
@ -168,10 +168,12 @@ with all sufficient information, see the ChangeLog file.
|
||||||
* Matrix#unitary?
|
* Matrix#unitary?
|
||||||
* Matrix#upper_triangular?
|
* Matrix#upper_triangular?
|
||||||
* Matrix#zero?
|
* Matrix#zero?
|
||||||
|
* Vector#magnitude
|
||||||
* extended methods:
|
* extended methods:
|
||||||
* Matrix#each and #each_with_index can iterate on a subset of the elements
|
* Matrix#each and #each_with_index can iterate on a subset of the elements
|
||||||
* Matrix#find_index returns [row, column] and can iterate on a subset
|
* Matrix#find_index returns [row, column] and can iterate on a subset
|
||||||
of the elements
|
of the elements
|
||||||
|
* Matrix.zero can build rectangular matrices
|
||||||
|
|
||||||
* net/http
|
* net/http
|
||||||
* SNI (Server Name Indication) supported for HTTPS.
|
* SNI (Server Name Indication) supported for HTTPS.
|
||||||
|
|
|
@ -229,13 +229,14 @@ class Matrix
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Creates an +n+ by +n+ zero matrix.
|
# Creates a zero matrix.
|
||||||
# Matrix.zero(2)
|
# Matrix.zero(2)
|
||||||
# => 0 0
|
# => 0 0
|
||||||
# 0 0
|
# 0 0
|
||||||
#
|
#
|
||||||
def Matrix.zero(n)
|
def Matrix.zero(row_size, column_size = row_size)
|
||||||
Matrix.scalar(n, 0)
|
rows = Array.new(row_size){Array.new(column_size, 0)}
|
||||||
|
new rows, column_size
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -1723,9 +1724,10 @@ class Vector
|
||||||
# Returns the modulus (Pythagorean distance) of the vector.
|
# Returns the modulus (Pythagorean distance) of the vector.
|
||||||
# Vector[5,8,2].r => 9.643650761
|
# Vector[5,8,2].r => 9.643650761
|
||||||
#
|
#
|
||||||
def r
|
def magnitude
|
||||||
Math.sqrt(@elements.inject(0) {|v, e| v + e*e})
|
Math.sqrt(@elements.inject(0) {|v, e| v + e*e})
|
||||||
end
|
end
|
||||||
|
alias r magnitude
|
||||||
|
|
||||||
#--
|
#--
|
||||||
# CONVERTING
|
# CONVERTING
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue