Project

General

Profile

Actions

Bug #2582

closed

wrong determinant is calculated for matrix

Added by tammo (tammo tjarks) over 14 years ago. Updated almost 13 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]
[ruby-core:27507]

Description

=begin
when I calculate the determinant of the matrix
2 0 1
0 -2 2
1 2 3

i get with:
irb(main):001:0> require 'matrix'
=> true
irb(main):002:0> a = Matrix2,0,1],[0,-2,2],[1,2,3
=> Matrix2, 0, 1], [0, -2, 2], [1, 2, 3
irb(main):003:0> a.det
=> -20

but it should be -18
=end

Actions #1

Updated by yugui (Yuki Sonoda) over 14 years ago

  • Status changed from Open to Rejected

=begin
It is because 1/2 == 0 -- in Ruby 1.8. You need to require 'mathn' to get a correct determinant for a matrix over integer.
Or you can give the matrix as a matrix over float:
Matrix2.0, 0.0, 1.0], [0.0, -2.0, 2.0], [1.0, 2.0, 3.0.det #=> -18.0,
or you can use Ruby 1.9:
% ruby -rmatrix -ve 'p Matrix2, 0, 1], [0, -2, 2], [1, 2, 3.det'
ruby 1.9.1p375 (2009-12-05 revision 26021) [i386-darwin9.8.0]
(-18/1)
=end

Actions

Also available in: Atom PDF

Like0
Like0