Matrix: exchange rows + exchange columns

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…

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs