MathGroup Archive 2005

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

Search the Archive

Re: Function to handle array with variable _number_ of dimensions?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg58539] Re: Function to handle array with variable _number_ of dimensions?
  • From: Joe Christy <joe at eshu.net>
  • Date: Wed, 6 Jul 2005 03:11:23 -0400 (EDT)
  • References: <dad7t1$36$1@smc.vnet.net> <42CA68A5.90802@metrohm.ch>
  • Sender: owner-wri-mathgroup at wolfram.com

  Vis-a-vis Daniel's note of 07/05/2005 04:01 AM:
> Hi Joe,
> if you want a descent answer, please try to phrase your question that it
> becomes sensible.
> You have 2 integer arguments, P and Q. Why is PxPx..xP an array? What
> does x mean? Is P an array?
> ...

	Sorry to be unclear. P is an Integer and x means "by" in my original
post (at the end of this post), so PxPx...xP is not an array itself, but
rather describes the size and shape of an array.

	I want to compute various quantities derived from a Q-dimensional array
of P^Q integers, where not only the individual integers, but also their
position within the array matters.
	E.G.
In the case P=7 and Q=2 a typical array of 49 integers is:
2    45   32   31   28   22   43

39   3    40   30   5	 36   10

29   6    16   27   15   34   12

4    7    8    21   26   19   46

35   20   24   42   14   23   37

9    25   48   1    33   41   17

38   18   0    44   11   13   47
and a typical quantity would be the average, over the entire array, of
the function which assigns to, for example, the middle cell the value
21*[(26+27+8+42)/4 + (19/2+15/2+30/2+16/2+7/2+24/2+1/2+14/2)/8 +
(46/3+34/3+...+23/3)/12 + ...], i.e. its value times the sum over
consecutive diamond-shaped shells of the averages of the other values in
that shell, weighted by the reciprocal of their taxicab distance from
the middle cell.

Or, in the case P=3 and Q=4, the array (of 81 integers) might be:
4  52 18   68 69 77   46 8  30
79 32 20   76 47 24   23 73 13
66 62 55   67 5  0    75 34 49

33 63 53   7  36 64   72 39 60
48 6  70   29 28 37   12 44 58
74 35 9    45 27 40   22 26 15

61 59 16   51 57 2    31 14 50
54 71 10   17 11 42   19 21 56
65 38 41   3  43 80   78 25 1
and the quantity might be the sum of the values of a function on the
array, which, at the cell with coordinates (1,2,3,2), depends on the the
numbers 12 (at that cell) and 19, 22, 44, 72, 23, and 29 in the
immediately adjacent cells, for instance
(12-19)+(12-22)+(12-44)+(12-72)+(12-23)+(12-29).

	The point is that once I am given P and Q, I know how to compute the
P^Q values in the array, but what I want to do is calculate a sort of
integral over the entire array of the values "smeared" by a sort of
kernel function of the Q coordinates.

	In other words, I'd like to write a function like:
F[P_Integer,Q_Integer]:=
Sum[
	g[P,Q,z1,z2, ... ,zQ],
	{z1,0,P},{z2,0,P}, ... ,{zQ,0,P}
]
where I have already defined
g[P_Integer,Q_Integer,zList__Integer]:=
SomeExpression/;Length[zList]==Q
My problem is that I don't know how, in Mathematica, to "handle the
ellipsis" in order to allow for the variable number, Q, of indices for
the array.

> Joe Christy wrote:
> 
>> I'd like to write a function that takes two integer arguments, P and Q
>> say, and then returns a value calculated from the P x P x ... x P (Q
>> factors) array, whose entries depend on both P and Q. My first impulse
>> is to try and iterate over the array, but I don't see how to generate a
>>  non-fixed number of iteration variables.
>>
>> Does anyone have a suggestion of a good way to do this, short of writing
>> a a distinct variant function for each possible value of Q?
>>
> 

-- 
============================= Joe Christy ==============================
------------------ http://public.xdi.org/=joe.christy ------------------
== If I can save you any time, give it to me, I'll keep it with mine. ==


  • Prev by Date: Re: How to simulate random samples from crooked coin toss?
  • Next by Date: Re: Partial diff equations
  • Previous by thread: Re: Function to handle array with variable _number_ of dimensions?
  • Next by thread: Re: Function to handle array with variable _number_ of dimensions?