Re: Building a matrix

• To: mathgroup at smc.vnet.net
• Subject: [mg132741] Re: Building a matrix
• From: Bob Hanlon <hanlonr357 at gmail.com>
• Date: Mon, 19 May 2014 20:15:45 -0400 (EDT)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• Delivered-to: l-mathgroup@wolfram.com
• Delivered-to: mathgroup-outx@smc.vnet.net
• Delivered-to: mathgroup-newsendx@smc.vnet.net
• References: <20140519060351.582BA6A9A@smc.vnet.net>

```Clear[f1, f2]

f1[m_List, n_List] := NestList[
RotateRight[#, 3] &, {n, m, m} // Flatten, 2]

f2[m_List, n_List] :=
Flatten /@
(Permutations[{a, b, b}, {3}] /.
{a -> n, b -> m})

m = {0, 0, 0};
n = {1, 2, 3};

f1[m, n]

{{1, 2, 3, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 2, 3, 0, 0, 0}, {0, 0, 0, 0, 0,
0,
1, 2, 3}}

f2[m, n]

{{1, 2, 3, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 2, 3, 0, 0, 0}, {0, 0, 0, 0, 0,
0,
1, 2, 3}}

% == %%

True

Bob Hanlon

On Mon, May 19, 2014 at 2:03 AM, Bruno Campanini <brunocam at libero.it> wrote:

> Given:
>
> m = [0,0,0}
> n = {1,2,3}
>
> how can I get a function to give:
>
> {{1,2,3,0,0,0,0,0,0}, {0,0,0,1,2,3,0,0,0}, {0,0,0,0,0,0,1,2,3}}
>
> ???
>
> Bruno
>
>

```

• Prev by Date: Re: Building a matrix
• Next by Date: Re: Building a matrix
• Previous by thread: Re: Building a matrix
• Next by thread: Re: Building a matrix