MathGroup Archive 2002

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

Search the Archive

Re: How to speed up this calculation?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg37261] Re: [mg37200] How to speed up this calculation?
  • From: Sseziwa Mukasa <mukasa at jeol.com>
  • Date: Mon, 21 Oct 2002 02:29:22 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On Wednesday, October 16, 2002, at 02:26 PM, Cheng Liu wrote:

> Dear group,
>
>          I have the following question regarding a lengthy calculation
> using Mathematica:
>
> For given w points in x direction and h points in y direction, I can
> construct all the points using
>
>          h=10; w=8;
>          points=Flatten[Transpose[Outer[List,Range[w],Range[h]]],1]
>
> Next, I need to find all the possible pairs of point including points
> themselves, i.e., pair AA.  I can use
>
>          pairs=Outer[List,points,points,1]
>
> Then, I have to clear those pairs that repeat themselves, i.e., pair 
> AB and
> pair BA.  Also, when w and h are of the order of 1000s, the computation
> takes a very long time.  Is there a better way of doing the second 
> part of
> the computation?  Thanks in advance.
>
>

Have you tried using the KSubsets function from 
DiscreteMath`Combinatorica`?  What you want are all KSubsets of length 
2 plus the original set of points duplicated for example:

Needs["DiscreteMath`Combinatorica`"]
pairs=Join[KSubsets[points,2],Transpose[{points,points}]]

Regards,

Sseziwa



  • Prev by Date: Re: Checking the Results of NDSolve
  • Next by Date: Quadratic non-linear ODE.
  • Previous by thread: Re: How to speed up this calculation?
  • Next by thread: Generatring EPS figures