Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2000

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

Search the Archive

Re: Could this be improved?

  • To: mathgroup at
  • Subject: [mg21787] Re: Could this be improved?
  • From: Paul Abbott <paul at>
  • Date: Thu, 27 Jan 2000 22:57:11 -0500 (EST)
  • Organization: University of Western Australia
  • References: <86mdpv$>
  • Sender: owner-wri-mathgroup at

Jordan Rosenthal wrote:

> 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];
>     vPadded = PadRight[v, nRows, 0];
>     For[i = 1, i <= nCols, i++,
>       c[[All, i]] = vPadded;
>       vPadded = RotateRight[vPadded]
>       ];
>     c
>     ]

You also need the definition of ZeroMatrix.

I think that the essential function you are after is NestList. The following
is slightly simpler:

 NewMtx[v_] := Module[
  {n = Length[v]},
    Reverse[PadRight[PadLeft[v, 2n-1], 3n-2]], 2n-2][[All, Range[2n-1, 3n-2]]]


  • Prev by Date: Re: Could this be improved?
  • Next by Date: Re: Efficient Replacement Rules to Matrix?
  • Previous by thread: Re: Could this be improved?
  • Next by thread: Re: Could this be improved?