MathGroup Archive 2004

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

Search the Archive

Re: Iterator problem.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg52335] Re: [mg52327] Iterator problem.
  • From: DrBob <drbob at bigfoot.com>
  • Date: Wed, 24 Nov 2004 02:32:06 -0500 (EST)
  • References: <200411230712.CAA29378@smc.vnet.net>
  • Reply-to: drbob at bigfoot.com
  • Sender: owner-wri-mathgroup at wolfram.com

The Table statement as you've written it (ignoring the syntax problem) suggests that you want i <= j <= k. If so, the table can be written in a couple of ways, equivalent except for order:

one=Table[a[i]+a[j]+a[k],{i,1,3},{j,i,3},{k,j,3}]//Flatten
two=Table[a[i]+a[j]+a[k],{k,1,3},{j,1,k},{i,1,j}]//Flatten
Sort@one==Sort@two

{3 a[1],2 a[1]+a[2],2 a[1]+a[3],a[1]+2 a[2],a[1]+a[2]+a[3],a[1]+2 a[3],3
     a[2],2 a[2]+a[3],a[2]+2 a[3],3 a[3]}

{3 a[1],2 a[1]+a[2],a[1]+2 a[2],3 a[2],2 a[1]+a[3],a[1]+a[2]+a[3],2 a[2]+a[3],
   a[1]+2 a[3],a[2]+2 a[3],3 a[3]}

True

If you wanted i < j < k, the table is either of these:

one=Table[a[i]+a[j]+a[k],{i,1,3},{j,i+1,3},{k,j+1,3}]//Flatten
two=Table[a[i]+a[j]+a[k],{k,1,3},{j,1,k-1},{i,1,j-1}]//Flatten
Sort@one==Sort@two

{a[1]+a[2]+a[3]}

{a[1]+a[2]+a[3]}

True

(That's a hard way to do it, of course.)

Bobby

On Tue, 23 Nov 2004 02:12:46 -0500 (EST), Robert G. Wilson v <rgwv at rgwv.com> wrote:

> Hello,
>
> 	I am having a problem with iterators in Mathematica.
> 	
> 	I have a sequence of integers defined by a[n]. I wish to build a table
> of integers out of the above such that this table only contains integers of
> the form a(i)+a(j)+a(k).
>
> 	I tried Table[a[i] + a[j] + a[k], {k, 1, 3}, {j, i, k}, {i, 1, j}] but
> the iterators do not have appropriate bounds.
>
> 	Any help would be greatly appreciated.
>
> Sincerely,
>
> Bob.
>
>
>
>



-- 
DrBob at bigfoot.com
www.eclecticdreams.net


  • Prev by Date: Re: UnitStep
  • Next by Date: Re: MikTeX 2.4, Mathematica 5.0 and fonts
  • Previous by thread: Re: Iterator problem.
  • Next by thread: Re: Iterator problem.