       Could this be improved?

• To: mathgroup at smc.vnet.net
• Subject: [mg21741] Could this be improved?
• From: "Jordan Rosenthal" <jr at ece.gatech.edu>
• Date: Wed, 26 Jan 2000 03:45:40 -0500 (EST)
• Organization: Georgia Institute of Technology, Atlanta GA, USA
• Sender: owner-wri-mathgroup at wolfram.com

```Hi all,

I wrote the following code which works correctly.  I was wondering, however,
if there was a way of doing the same thing that had more of a Mathematica
approach.  I am new to Mathematica and am still trying to get a grasp on how
to program effectively within the environment.

myMtx[v_] := Module[
{nCols, nRows, vPadded, c},
nCols = Length[v];
nRows = 2nCols - 1;
c = ZeroMatrix[nRows, nCols];
For[i = 1, i <= nCols, i++,
c[[All, i]] = vPadded;
];
c
]

For example, myMtx[{1,2,3}] takes the vector {1,2,3} and turns it into the
matrix {{1, 0, 0}, {2, 1, 0}, {3, 2, 1}, {0, 3, 2}, {0, 0, 3}} which looks
like

[ 1 0 0 ]
[ 2 1 0 ]
[ 3 2 1 ]
[ 0 3 2 ]
[ 0 0 3 ]

Thanks,

Jordan

```

• Prev by Date: Re: Product with p!=j
• Next by Date: Re: Mathematica on the Web
• Previous by thread: Re: Efficient Replacement Rules to Matrix?
• Next by thread: Re: Could this be improved?