Search All of the Math Forum:

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Replies: 0

 Steve Sutlief Posts: 2 Registered: 12/7/04
Posted: Aug 25, 1996 6:02 PM

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?

I looked at the command \$PreRead (and \$Pre), but I could only think
of a way to use this for one dimensional arrays. For an array "b":

\$PreRead = StringReplace[#, {"b[[" -> "b[[6+"}] &

The two kludges I could use in C won't work in Mathematica:

#include <stdio.h>

#define b(x) a[x+5]

main ()
{
int a[11] = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
int i, *c = a+5;

for (i = -5; i < 6; i++)
printf("a[%2d] = %d, b(%2d) = %d, c[%2d] = %d\n",
i+5, a[i+5], i, b(i), i, c[i]);

return 0;
}

Steve Sutlief
--
Steve Sutlief, Ph.D. project: dynamic conformal radiation therapy