MathGroup Archive 2009

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

Search the Archive

Re: simpler way to get a particular banded matrix?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg98107] Re: simpler way to get a particular banded matrix?
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Mon, 30 Mar 2009 04:44:26 -0500 (EST)

On 3/29/09 at 2:48 AM, bitbucket at comcast.net (rip pelletier) wrote:

>The following command constructs a matrix (typically denoted M0, it
>arises in filter banks in general, in Burrus, Gopinath, & Guo "intro
>to wavelets and wavelet transforms: a primer" in particular).

>I'm sure there's a way to do this without typing out all 5 bands.
>Here's what i did:

>SparseArray[Band[{1,1}]->H,{6,6}]+
>SparseArray[Band[{2,3}]->H,{6,6}]+
>SparseArray[Band[{3,5}]->H,{6,6}]+
>SparseArray[Band[{-2,-3},{1,1},{-1,-1}]->rH,{6,6}]+
>SparseArray[Band[{-3,-5},{1,1},{-1,-1}]->rH,{6,6}]

>where

>H={h0,h1,h2,h3,h4,h5}; rH=Reverse[H];

>I get what I want:

>h0  0  0  0  0  0
>h2 h1 h0 0  0  0
>h4 h3 h2 h1 h0 0
>0  h5 h4 h3 h2 h1
>0  0  0  h5 h4 h3
>0  0  0  0  0  h5

>Any easier ways to get this?

You can include a list of bands rather than summing separate
arrays with a single band specified. That is:

In[17]:= s =
   SparseArray[Band[{1, 1}] -> H, {6, 6}] +
    SparseArray[Band[{2, 3}] -> H, {6, 6}] +
    SparseArray[Band[{3, 5}] -> H, {6, 6}] +
    SparseArray[Band[{-2, -3}, {1, 1}, {-1, -1}] -> rH, {6, 6}] +
    SparseArray[Band[{-3, -5}, {1, 1}, {-1, -1}] -> rH, {6, 6}];

In[18]:= s ==
  SparseArray[{Band[{1, 1}] -> H, Band[{2, 3}] -> H[[;; 4]],
    Band[{3, 5}] -> H[[;; 2]], Band[{2, 1}] -> H[[3 ;;]],
    Band[{3, 1}] -> H[[5 ;;]]}]

Out[18]= True

Note, I've also omitted specifying the array dimensions since
this is fixed by the main diagonal and I have specified the off
main diagonal bands to use just the part of H needed which
eliminates the warning messages your code generates. However, I
still specified each of the bands. So, this may not satisfy your
criteria for easier.



  • Prev by Date: Re: Image Processing & 3D Graphics Question
  • Next by Date: Re: Default Lighting Colors and Positions
  • Previous by thread: Re: simpler way to get a particular banded matrix?
  • Next by thread: Re: simpler way to get a particular banded matrix?