Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1998
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

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

Search the Archive

Re: Block diagonal systems

  • To: mathgroup at smc.vnet.net
  • Subject: [mg13592] Re: Block diagonal systems
  • From: Rolf Mertig <rolf at mertig.com>
  • Date: Mon, 3 Aug 1998 03:53:52 -0400
  • Organization: Mertig Research & Consulting
  • References: <6puia4$6t2@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

michael ringor wrote:

> Hello:  Does anyone have an efficient way of creating a block
>     diagonal matrix, where the matrices along the diagonal are
>     identical m by n matrices?  I'm looking for some sort of
>     generalization to DiagonalMatrix[list] where list is sequence of
>     compatible matrices, instead of a scalar list.
>
> Michael Ringor
> Purdue University


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];

In[2]:= BlockDiagonalMatrix[{{{1,2},{3,4}},{{1,2},{3,4}}}]//MatrixForm

Out[2]//MatrixForm=
                    1   2   0   0

                    3   4   0   0

                    0   0   1   2

                    0   0   3   4

In[3]:=
BlockDiagonalMatrix[{{{1,2},{3,4},{5,6}},{{x,x},{x,x}},{{u}}}]//MatrixForm

Out[3]//MatrixForm=
                    1   2   0   0   0

                    3   4   0   0   0

                    5   6   0   0   0

                    0   0   x   x   0

                    0   0   x   x   0

                    0   0   0   0   u


Rolf




  • Prev by Date: What is the fastest machine for Mathematica?
  • Next by Date: Re: System of differential equations
  • Previous by thread: Re: Block diagonal systems
  • Next by thread: Re: Block diagonal systems