Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Re: Building a matrix
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
Alexei Boulbitch

Posts: 483
Registered: 2/28/08
Re: Building a matrix
Posted: May 21, 2014 4:14 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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

Hi, Bruno,

You might do like the following, for example:

Map[Flatten, Table[RotateRight[{n, m, m}, i], {i, 0, 2}]]

Returning
{{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}}
As you want, or a bit shorter:

Flatten /@ (RotateRight[{n, m, m}, #] & /@ {0, 1, 2})

Returning the same.

Have fun, Alexei

Alexei BOULBITCH, Dr., habil.
IEE S.A.
ZAE Weiergewan,
11, rue Edmond Reuter,
L-5326 Contern, LUXEMBOURG

Office phone : +352-2454-2566
Office fax: +352-2454-3566
mobile phone: +49 151 52 40 66 44

e-mail: alexei.boulbitch@iee.lu






Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.