Re: simpler way to get a particular banded matrix?
- To: mathgroup at smc.vnet.net
- Subject: [mg98094] Re: simpler way to get a particular banded matrix?
- From: Raffy <raffy at mac.com>
- Date: Mon, 30 Mar 2009 04:42:01 -0500 (EST)
- References: <gqn910$2o$1@smc.vnet.net>
On Mar 29, 12:46 am, rip pelletier <bitbuc... at comcast.net> wrote: > Hi, > > 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? > > TIA and vale, > rip > > -- > NB eddress is r i p 1 AT c o m c a s t DOT n e t To error on the side of readability, I'd probably go with: mat[n_Integer] := With[ {vRow = Join[ ConstantArray[0, n - 1], Table[ToExpression["h" <> ToString[i]], {i, n - 1, 0, -1}], ConstantArray[0, n - 1]] }, Table[Take[vRow, {2 n + 1, 3 n} - 2 i], {i, n}] ];