matrix: exchange rows + exchange columns

  • Follow


Hi all, I wrote two new method for exchange 2 row (2 columns) in a
matrix:


class Matrix
     def exchange_rows(i,j)
  a = Matrix.rows(@rows) # matrice originale
  b = a.clone() # matrice di servizio
  for k in 0...a.column_size
    a[i,k] = b[j,k]
    a[j,k] = b[i,k]
  end
  return a
  end

  def exchange_columns(i,j)
  a = Matrix.rows(@rows) # matrice originale
  b = a.clone() # matrice di servizio
  for k in 0...a.row_size
    a[k,i] = b[k,j]
    a[k,j] = b[k,i]
  end
  return a
end


I hope it is usefull to you....

-- 
Posted via http://www.ruby-forum.com/.

0
Reply Alessandro 1/25/2011 7:26:04 PM


0 Replies
549 Views

(page loaded in 0.029 seconds)

Similiar Articles:













7/25/2012 12:01:44 AM


Reply: