From: Niko Schwarz Date: 2001-10-21T02:07:34+09:00 Subject: [ruby-talk:22838] array prob I still have probs with ruby, i hope you can find me, it wont take long, promise! ,----[ ng.rb ] | require "matrix.rb" | | def solveGauss(a) | tri = Array.new | 0.upto(a.length-1) { |s| | a = a.sort { |a, b| thats the first problem. what you see is a workaround, but i dont get why a.sort! { bla... doesnt work. | b[s].abs <=> a[s].abs | } | fail("Pivotelement ist 0") if a[0][s] == 0 and here goes the second problem. for some weird reason which ive been trying to find the whole afternoon, a[0] is a fixnum in run 2. | tri.push a.shift | a.map! { |elt| | faktor = (-a[0][s]) / tri[tri.length-1][s] | 0.upto(elt.length-1) { |i| | elt[i] += ( tri[tri.length-1][i] * faktor) | } | } | } | print Matrix.rows(tri), "\n", Matrix.rows(a), "\n" | end | | print "give matrix\n" | | read = Array.new | while str = STDIN.gets | read.push( str.split(",").map! {|elt| elt.to_f}) | end | | print "sol vector plz\n" | b = STDIN.gets.split(",").map! {|elt| elt.to_f} | | for e in read | e.push b.shift | end | | solveGauss(read) | `---- i tried it always with the matrix 1,2 3,4 and the solution vector 5,6. its supposed to be the gaussian algorithm, well, at least the first 2 steps. please help me, ive been trying to solve this since ~6h. regards, nick -- Technological progress has merely provided us with more efficient means for going backwards. -- Aldous Huxley