Re: simpler way to get a particular banded matrix?
- To: mathgroup at smc.vnet.net
- Subject: [mg98147] Re: simpler way to get a particular banded matrix?
- From: rip pelletier <bitbucket at comcast.net>
- Date: Tue, 31 Mar 2009 04:19:57 -0500 (EST)
- References: <gqq3um$7ni$1@smc.vnet.net>
In article <gqq3um$7ni$1 at smc.vnet.net>,
Bill Rowe <readnews at sbcglobal.net> wrote:
> 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.
Thank you. It goes a long way toward letting me generalize this matrix,
and you showed me how to do some things I didn't know. I appreciate
this. Conceptually, I grok this matrix from its bands, rather than from
its rows or columns.
Vale,
Rip
--
NB eddress is r i p 1 AT c o m c a s t DOT n e t