MathGroup Archive 2002

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

Search the Archive

Re: Switch rows!

  • To: mathgroup at smc.vnet.net
  • Subject: [mg32378] Re: Switch rows!
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Thu, 17 Jan 2002 02:23:31 -0500 (EST)
  • Organization: Universitaet Leipzig
  • References: <a23fhk$9le$1@smc.vnet.net>
  • Reply-to: kuska at informatik.uni-leipzig.de
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

a) pivoting work with a pivot array, that avoid the 
   explicit copy/exchange operation of rows ...
   the rows are accessed as matrix[[pivot[[i]]]] instead of
   matrix[[i]] and "exchanging" a row is an exchange
   of the two integers in pivot and not an exchange of 
   the m numbers in a row.

b) You have to use the HoldFirst attribute:

SetAttributes[RowSwap,HoldFirst]

RowSwap[ matrix_, row1_Integer, row2_Integer ] :=
  Block[{tmp = matrix[[row1]]},  
     matrix[[row1]]=matrix[[row2]];
     matrix[[row2]]=tmp; 
    ]
 
Regards
  Jens


> _____________
Rebeka Renko wrote:
> 
> Hi!
> 
> I have another question. While I was writting a
> program for partial pivoting, I used a program bellow
> for switching rows in a matrix. It works fine, when I
> use it separetly, but if I include it into a programm,
> it returns an error. I believe this is because of the
> BLOCK command, or am I wrong? How can it be changed,
> so that it would fit my programm?
> I am looking forward on your answer and am thanking
> you in advance!
> 
> Regards,
> Rebeka
> 
> Programm:
> RowSwop[ matrix_, row1_, row2_ ] :=
> Block[{temp = matrix}, temp[[row1]] = matrix[[row2]];
>     temp[[row2]] = matrix[[row1]]; temp ]
> 
> __________________________________________________
> Do You Yahoo!?
> Send FREE video emails in Yahoo! Mail!
> http://promo.yahoo.com/videomail/


  • Prev by Date: Comparison of Mathematica on Various Computers
  • Next by Date: RE: How To Change A Rule
  • Previous by thread: Switch rows!
  • Next by thread: Taylor Series Expansions