Project

General

Profile

This project is closed and read-only.

Actions

Bug #2582

closed

wrong determinant is calculated for matrix

Bug #2582: wrong determinant is calculated for matrix

Added by tammo (tammo tjarks) over 16 years ago. Updated over 15 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 = Matrix[[2,0,1],[0,-2,2],[1,2,3]]
=> Matrix[[2, 0, 1], [0, -2, 2], [1, 2, 3]]
irb(main):003:0> a.det
=> -20

but it should be -18
=end

Updated by yugui (Yuki Sonoda) over 16 years ago Actions #1

  • 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:
Matrix[[2.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 Matrix[[2, 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: PDF Atom