Re: simpler way to get a particular banded matrix?
- To: mathgroup at smc.vnet.net
- Subject: [mg98205] Re: simpler way to get a particular banded matrix?
- From: Nicholas <physnick at gmail.com>
- Date: Thu, 2 Apr 2009 04:48:55 -0500 (EST)
- References: <gqq3um$7ni$1@smc.vnet.net> <gqsn7a$3rn$1@smc.vnet.net>
On Mar 31, 5:19 am, rip pelletier <bitbuc... at comcast.net> wrote: > In article <gqq3um$7n... at smc.vnet.net>, > Bill Rowe <readn... at sbcglobal.net> wrote: > > > > > On 3/29/09 at 2:48 AM, bitbuc... 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 What about: M0 = Table[ Total@Table[ H[[k]] KroneckerDelta[2 i - 1, j + k - 1], {k, 1, 6}], {i, 1, 6}, {j, 1, 6}] This is a little different from the others, but it might be more straight forward. I don't know how it scales though. Nick.