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 2007

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

Search the Archive

Re: matrices with arbitrary dimensionality

  • To: mathgroup at
  • Subject: [mg76739] Re: matrices with arbitrary dimensionality
  • From: Ray Koopman <koopman at>
  • Date: Sat, 26 May 2007 04:46:20 -0400 (EDT)
  • References: <f36ea9$7tn$>

On May 25, 3:38 am, " at" < at>
> Hi there,
> with V.6.0 I keep on with my experiment in translating a large C++
> spin simulation program.
> What I'm bouncing my head against today is the following:
> there is a way in M to describe objects (matrices) having an arbitrary
> number of dimensions, defined just at runtime?
> In detail, I work on an orthogonal lattice where my spins are defined,
> but the simulations require sometimes to deal with 1d (arrays),
> sometimes more.
> Yet I'd like to write the most general code it is possible, e.g. when
> writing a procedure that - given a location in the lattice at the
> coordinates {i,j,...} - returns a list of locations of the nearest
> neighbors
> (in 1d: {{i-1},{i+1}}; in 2d: {{i-1,j},{i+1,j},{i,j-1},{i,j+1}} and so
> on...)
> thanks for any hint...
> Alessandro Magni

neighbors[v_List?VectorQ] := Flatten[{v-#,v+#}& /@


  • Prev by Date: Re: Function as an argument
  • Next by Date: Re: fun with 6.0 graphics
  • Previous by thread: Re: matrices with arbitrary dimensionality
  • Next by thread: Re: matrices with arbitrary dimensionality