From 3b51e3a11fd39daafaaaf54bcbf81814d48c3942 Mon Sep 17 00:00:00 2001 From: stomar Date: Thu, 11 Jan 2018 19:36:30 +0000 Subject: 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 --- lib/matrix.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib/matrix.rb') diff --git a/lib/matrix.rb b/lib/matrix.rb index 923e716b35..4a61976b0e 100644 --- a/lib/matrix.rb +++ b/lib/matrix.rb @@ -801,6 +801,18 @@ class Matrix true 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. -- cgit v1.2.3