MathGroup Archive 2009

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

Search the Archive

Re: Loop programming; how do i do this ???

  • To: mathgroup at smc.vnet.net
  • Subject: [mg96095] Re: Loop programming; how do i do this ???
  • From: "Sjoerd C. de Vries" <sjoerd.c.devries at gmail.com>
  • Date: Thu, 5 Feb 2009 04:37:08 -0500 (EST)
  • References: <gmbr29$igp$1@smc.vnet.net>

Not sure what TEST does, so the following may or may not work for
you.

A short way of having TEST act on all combinations of the selected 2D
array elements would be:

TEST @@@ Tuples[DArrayCon[[DArrayVar]]]

Note that variable names cannot start with a number in Mathematica
(and in many other programming languages) so I have removed the 1 and
2 from your names.

Note also that TEST should be able to handle a variable number of
arguments.

Cheers -- Sjoerd


On Feb 4, 12:35 pm, plzhlp <n... at live.be> wrote:
> I need to implement a function into my notebook but am having great diffi=
culties even getting started (i'm new to mathematica and programming in gen=
eral)
>
> The function accepts a 1d array (of variable length) of integers
>
> which will refer to a 2d array of constants, of which all need to be test=
ed against eachother.
>
> for example:
>
> 1DArrayVar = {2, 4, 5}
>
> 2DArrayCon = {
>              {a1,b1,c1},
>              {a2,b2,c2},
>              {a3,b3,c3},
>              {a4,b4,c4},
>              {a5,b5,c5}
>              }
>
> Function[1DArrayVar]
>
> in this scenario will test:
>
> Do[
>   Do[
>     Do[
>
> TEST[2DArrayCon[[2,x]],2DArrayCon[[4,y]],2DArrayCon[[5,z]]]
>
>     , {x, Length[DArrayCon[[2]]]
>   , {y, Length[DArrayCon[[4]]]
> , {z, Length[DArrayCon[[5]]]
>
> So basically the problem is that i need a variable amount of nested loops=
, as the length of 1DArrayVar will always be unknown.
>
> >From some research on the internet i've learned a recursive algorithm mi=
ght be the solution, but i am completely lost on how to start --
>
> any tips would be really appreciated !



  • Prev by Date: Re: Loop programming; how do i do this ???
  • Next by Date: Re: Mathematica 7 benchmarks on Suse 11
  • Previous by thread: Re: Loop programming; how do i do this ???
  • Next by thread: Split Screen Redux