diff options
author | stomar <stomar@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-01-11 19:36:30 +0000 |
---|---|---|
committer | stomar <stomar@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-01-11 19:36:30 +0000 |
commit | 3b51e3a11fd39daafaaaf54bcbf81814d48c3942 (patch) | |
tree | e3dbd876041db9bbd86d460b2a24f0347b574778 /lib/matrix.rb | |
parent | 9e677261a9147616c32bb32004fcf99e868563d7 (diff) |
matrix.rb: add Matrix#antisymmetric?
* lib/matrix.rb: add Matrix#antisymmetric?.
Proposed by Yilo (@yiloo). Patch by Marcus Stollsteimer (@stomar).
[Fix GH-1788]
* spec/ruby/library/matrix/antisymmetric_spec.rb: add specs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61775 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/matrix.rb')
-rw-r--r-- | lib/matrix.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/matrix.rb b/lib/matrix.rb index 923e716b35..4a61976b0e 100644 --- a/lib/matrix.rb +++ b/lib/matrix.rb @@ -802,6 +802,18 @@ class Matrix end # + # Returns +true+ if this is an antisymmetric matrix. + # Raises an error if matrix is not square. + # + def antisymmetric? + Matrix.Raise ErrDimensionMismatch unless square? + each_with_index(:upper) do |e, row, col| + return false unless e == -rows[col][row] + end + true + end + + # # Returns +true+ if this is a unitary matrix # Raises an error if matrix is not square. # |