MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: basic operations in matrices

  • To: mathgroup at smc.vnet.net
  • Subject: [mg34569] RE: [mg34542] basic operations in matrices
  • From: "DrBob" <majort at cox-internet.com>
  • Date: Wed, 29 May 2002 02:44:08 -0400 (EDT)
  • Reply-to: <drbob at bigfoot.com>
  • Sender: owner-wri-mathgroup at wolfram.com

Christian,

In the following, I've generated a matrix of symbols (m).  Then I show m
first with the second and third columns switched, then with the second
and third rows switched.

Remove["Global`*"]
letters = {"a", "b", "c", "d"};
m = (Unique /@ letters) & /@ Range[4];
m // MatrixForm
m[[All, {1, 3, 2, 4}]] // MatrixForm
m[[{1, 3, 2, 4}, All]] // MatrixForm

There are other ways, but I think this is the easiest.

Here are functions to switch any two rows or columns.  (This may not be
the easiest way, but it's an interesting way!)

<< DiscreteMath`Combinatorica`
pair[i_, j_, n_] :=
  FromCycles[Join[{{i, j}}, Complement[ToCycles[Range[n]], {#} & /@ {i,
j}]
      ]
    ]
rowSwitch[m_, i_, j_] := m[[pair[i, j, Length[m]], All]]
columnSwitch[m_, i_, j_] := m[[All, pair[i, j, Length[m]]]]
rowSwitch[m, 1, 3] // MatrixForm
columnSwitch[m, 1, 3] // MatrixForm
rowSwitch[columnSwitch[m, 1, 3], 2, 4] // MatrixForm

Bobby Treat

-----Original Message-----
From: Christian Junk [mailto:junkc at fh-trier.de] 
To: mathgroup at smc.vnet.net
Subject: [mg34569] [mg34542] basic operations in matrices

Hi!

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,

Christian





  • Prev by Date: Re: Inserting Mathematica-generated EPS files into PowerPoint? (on a Mac)
  • Next by Date: RE: A question about Mathematica
  • Previous by thread: RE: basic operations in matrices
  • Next by thread: RE: basic operations in matrices