MathGroup Archive 1998

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

Search the Archive

Re: Block diagonal systems


Rolf Mertig wrote:

> One possibility is:
> 
> In[1]:= BlockDiagonalMatrix[mat_List /;
>      And @@ (MatchQ[Dimensions[#1], {_, _}] & ) /@ mat, fillit_:0] :=
>    Module[{b = {0,0}, f, m}, f[{x_,y_}][e_, {r_, s_}] :=
>       Set @@ {m[r + x, s + y], e};
>      Do[MapIndexed[f[b], mat[[i]], 2]; b+= Dimensions[mat[[i]]],
>       {i, Length[mat]}]; Array[m, b] /. m[_, _] -> fillit];

Nice solution. As a slight improvement, you can replace

  mat_List /; And @@ (MatchQ[Dimensions[#1], {_, _}] & ) /@ mat

with

  mat:{_?MatrixQ..}

Cheers,
	Paul 

____________________________________________________________________ 
Paul Abbott                                   Phone: +61-8-9380-2734
Department of Physics                           Fax: +61-8-9380-1014
The University of Western Australia            Nedlands WA  6907       
mailto:paul at physics.uwa.edu.au  AUSTRALIA                       
http://www.physics.uwa.edu.au/~paul

            God IS a weakly left-handed dice player
____________________________________________________________________


  • Prev by Date: Re: What is the fastest machine for Mathematica?
  • Next by Date: MathGroup/Newsgroup Search Engine
  • Previous by thread: Re: Block diagonal systems
  • Next by thread: Mandelbrot