[Date Index] [Thread Index] [Author Index]
Re: can an "array" start with an index other than 1?
In article <4vqihp$qrn at dragonfly.wolfram.com>, Steve Sutlief <steve at gandalf.radonc.washington.edu> wrote: >I would like to have a multidimensional array with an index running >from -5 to 5, for example. Is there a kludge for doing this in >Mathematica? > >The two kludges I could use in C won't work in Mathematica: > >#define b(x) a[x+5] No? Why not define b[x_] := a[[x+6]] and use b[-5] to refer to a[], analogous to what you did in your C program? In fact, Mathematica can even make it look like b is being indexed, not called as a function (try getting this to work in C!), by doing this: b /: b[[x_]] := a[[x+6]] Now you can use b[[-5]], rather than b[-5], to refer to a[]. But the first way might even be prefereable to you, since it looks more like C and you're obviously a C programmer at heart. Dave Wagner Principia Consulting (303) 786-8371 dbwagner at princon.com http://www.princon.com/princon ==== [MESSAGE SEPARATOR] ====