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

• To: mathgroup at smc.vnet.net
• Subject: [mg96121] Re: Loop programming; how do i do this ???
• From: dh <dh at metrohm.com>
• Date: Thu, 5 Feb 2009 04:41:58 -0500 (EST)
• References: <gmbr29\$igp\$1@smc.vnet.net>

```
Hi,

in mathematica you rearly need loops. Instead you do things with

operators. Note that names can not start with an integer. Therefore I

First we need to assemble the rows of two that one indicates. This is

easily done:

res1=two[[one]]

Now we need to assemble all possible tuples having the the first element

from the first row, second element from second row:

res2= Tuples[res1]

Now we have all the requested arguments and map the function TEST onto them:

Apply[TEST,res2,2] or shorter:

TEST @@@ res2

Everything together on on line:

TEST @@@ Tuples[ two[[one]] ]

hope this helps, Daniel

plzhlp wrote:

> I need to implement a function into my notebook but am having great difficulties even getting started (i'm new to mathematica and programming in general)

>

> 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 tested 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 might 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: Implementation of Minimize for integer programming in Mathematica 7
• Previous by thread: Re: Loop programming; how do i do this ???
• Next by thread: Re: Loop programming; how do i do this ???