Re: basic operations in matrices
- To: mathgroup at smc.vnet.net
- Subject: [mg34593] Re: [mg34542] basic operations in matrices
- From: BobHanlon at aol.com
- Date: Wed, 29 May 2002 02:44:57 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
In a message dated 5/27/02 2:24:48 AM, junkc at fh-trier.de writes: >I'm new to Mathematica and I'm searching for an operation, that simply >transpose two rows or columns of a matrix M. > >e.g: > >Operation[M,{1,3}] > >1 1 1 1 3 3 3 3 >2 2 2 2 ---> 2 2 2 2 >3 3 3 3 1 1 1 1 >4 4 4 4 4 4 4 4 > >Much thanks in advance, > swapRows[mat_List, {r1_Integer?Positive, r2_Integer?Positive}] := ReplacePart[mat, mat, {{r1},{r2}}, {{r2},{r1}}] /; r1 <= Length[mat] && r2 <= Length[mat]; swapColumns[mat_List, {c1_Integer?Positive, c2_Integer?Positive}] := Module[{t=Transpose[mat]}, Transpose[ReplacePart[t, t, {{c1},{c2}}, {{c2},{c1}}]]] /; c1 <= Length[mat[[1]]] && c2 <= Length[mat[[1]]]; mat = Array[m,{4,4}]; swapRows[mat, {1,3}] swapColumns[mat, {1,3}] Bob Hanlon Chantilly, VA USA