MathGroup Archive 2014

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

Search the Archive

Re: Building a matrix


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