MathGroup Archive 2010

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

Search the Archive

Re: It would be nice to have DiagonalMatrix accept a matrix as building

  • To: mathgroup at smc.vnet.net
  • Subject: [mg113515] Re: It would be nice to have DiagonalMatrix accept a matrix as building
  • From: Mark Fisher <particlefilter at gmail.com>
  • Date: Mon, 1 Nov 2010 04:58:42 -0500 (EST)
  • References: <iajcai$p6j$1@smc.vnet.net> <iajg0g$qh1$1@smc.vnet.net>

On Oct 31, 6:22 am, Zach Bjornson <bjorn... at stanford.edu> wrote:
> (this is probably better submitted to Wolfram as a feature request,
> they're very responsive)
>
> You can use Band to avoid looping constructs:
>
> DiagonalM[block_, nBlocks_] :=
>   Normal@
>    SparseArray[Band[{1, 1}] -> ConstantArray[block, {nBlocks}]]
>
> I thought there was a still shorter version, but can't recall it...
>
> Best,
> Zach
>
> On 10/31/2010 2:19 AM, Nasser M. Abbasi wrote:
>
> > Sometime there is a need to make a matrix with repeating subblocks on
> > the diagonal.  For example, one might want to create matrix A, with
> > matrix B on its diagonal, repeated n times.
>
> > DiagonalMatrix only accepts vector (list), not matrix (list of lists),
> > as its argument.
>
> > So, one has the option to use DiagonalMatrix, repeatedly, using
> > different offsets at a time, and manually layout the diagonal. Or use
> > SparseArray since SparseArray accepts a matrix as the band, but also
> > make a loop to add the block at different locations on the diagonal.
>
> > The SparseArray method is little less work, but I think a nice solution
> > would be to have the ability to specify the block, and how many time it
> > needs to be repeated on the diagonal. That other 'system' has this
> > command to do that.
>
> > This is how I now create a diagonalMatrix with matrices at its diagonal=


  • Prev by Date: Re: Assertions in Mathematica?
  • Next by Date: Current BookChapterTitle and Section Names in Header?
  • Previous by thread: Re: Assertions in Mathematica?
  • Next by thread: Re: It would be nice to have DiagonalMatrix accept a matrix as building