matrix: exchange rows + exchange columns

  • Thread starter Alessandro Barracco
  • Start date
A

Alessandro Barracco

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....
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top