MathGroup Archive 2004

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

Search the Archive

Re: i don't understand mapping function over a long list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg47826] Re: [mg47802] i don't understand mapping function over a long list
  • From: Sseziwa Mukasa <mukasa at jeol.com>
  • Date: Thu, 29 Apr 2004 00:33:42 -0400 (EDT)
  • References: <200404270847.EAA18860@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On Apr 27, 2004, at 4:47 AM, sean kim wrote:

> hello group.
> please consider the following list of lists.
>
>
>
> l = Partition[Flatten[{Table[Unique[x], {n, 1, 30}]}], 3 ]
>
> above generates a list of 10 lists with 3 elements in each as in...
>
> {
> {x$299, x$300, x$301}, {x$302, x$303, x$304},
> {x$305, x$306, x$307}, {x$308, x$309, x$310},
> {x$311, x$312, x$313}, {x$314, x$315, x$316},
> {x$317, x$318, x$319}, {x$320, x$321, x$322},
> {x$323, x$324, x$325}, {x$326, x$327, x$328}
> }
>
> Now suppose I want to use each of the list( all 10 of them) as a part
> of a function. . I want to "Apply" the function to every list(so, 10
> times in total)
> for a simple examplel let's add 2 to the lists
>
> In[21]:= Apply[Plus@@xlist, 2]
> Out[21]= 2
>
> that didn't work. i wanted to get was
>
> {{x$299, x$300, x$301} + 2,
> {x$302, x$303, x$304} + 2...
> {x$326, x$327, x$328} + 2}}

I am not sure how to explain your error to you.  Suffice it to say this 
expression

#+2&/@xlist

will return what you want.

> then i want to give each of the results unique names and use the
> renamed list of lists as an argument in another function.
>
> {
> uniquexname1 = {x$299, x$300, x$301} + 2,
> uniquexname2 = {x$302, x$303, x$304} + 2...
> uniquexname10 = {x$326, x$327, x$328} + 2}
> }
>

Set[Evaluate[Unique[uniquename]],#]&/@xlist

You'll have to use Names["uniquename*"] to see the names of the 
variables in this case.

> and
>
> Map[Plus, xlist, 2]
>
> just bring back the list itself.

Again, I'm not sure what you mean.

> This problem recurs for me. and I think i have problems with it
> because I just don't understand how Mathematica language works.

It's a little different from other programming systems.

> Reading the book an dhelp manual doesn't help me much in understanding
> what lies underneath.  Can you guys shed soem light on this with some
> simple examples that use numerical operations?

I'm not sure a numerical example would be useful, your problem seems to 
be a misunderstanding of the nature of Mathematica expressions and the 
use of the operators Map and Apply.  The basic principle with Apply and 
Map is that every expression in Mathematica has a head (see help on 
Head) and body.  Map uses the elements of the body as arguments to a 
function which is its first argument.  Apply changes the head of an 
expression to another value.  You may also want to understand the idea 
of levels in Mathematica expressions, I suggest studying the operators 
TreeForm and Level as well as section A 3.6 and section 2 of the 
Mathematica Book.

> Maybe I'm asking a lot, but any and all insights are thoroughly
> appreciated.

I hope this helps,

Ssezi


  • Prev by Date: Re: bug in IntegerPart ?
  • Next by Date: PaddedForm bug?
  • Previous by thread: Re: i don't understand mapping function over a long list
  • Next by thread: RE: i don't understand mapping function over a long list