matrix: exchange rows + exchange columns

Discussion in 'Ruby' started by Alessandro Barracco, Jan 25, 2011.

  1. 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/.
    Alessandro Barracco, Jan 25, 2011
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. helpful sql
    Replies:
    0
    Views:
    791
    helpful sql
    May 19, 2005
  2. lvcargnini

    Matrix composed by two matrix

    lvcargnini, Jul 4, 2006, in forum: VHDL
    Replies:
    3
    Views:
    2,644
    Jonathan Bromley
    Jul 5, 2006
  3. kilter
    Replies:
    6
    Views:
    300
    Flash Gordon
    Aug 23, 2006
  4. Holgerson

    Matrix*Vector and Vector*Matrix

    Holgerson, Oct 25, 2007, in forum: C++
    Replies:
    3
    Views:
    396
    Holgerson
    Oct 26, 2007
  5. Terry Reedy
    Replies:
    0
    Views:
    541
    Terry Reedy
    Apr 2, 2009
Loading...

Share This Page