[Date Index]
[Thread Index]
[Author Index]
Re: i don't understand mapping function over a long list
*To*: mathgroup at smc.vnet.net
*Subject*: [mg47819] Re: i don't understand mapping function over a long list
*From*: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
*Date*: Wed, 28 Apr 2004 06:56:01 -0400 (EDT)
*Organization*: Universitaet Leipzig
*References*: <c6l7v9$iq0$1@smc.vnet.net>
*Reply-to*: kuska at informatik.uni-leipzig.de
*Sender*: owner-wri-mathgroup at wolfram.com
Hi,
a) you can't get {{x$299, x$300, x$301} + 2,..}
because Mathematica will distribute the scalar
addition over the lists an you will always end
with {{x$299+2, x$300+2, x$301+2},..}
b) you can use an new symbol that is not a List with
l = vector @@@ Partition[Flatten[{Table[Unique[x], {n, 1, 30}]}], 3];
and
l+2
c) you can assign the result to
unames = Table[Unique[u], {10}];
with
Set @@@ Transpose[{unames, (l + 2)}]
Regards
Jens
will produce the desired result.
sean kim wrote:
>
> hello group.
>
> i just don't get this.
>
> I'm not sure what's the problem is.
>
> 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}}
>
> 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}
> }
>
> and
>
> Map[Plus, xlist, 2]
>
> just bring back the list itself.
>
> This problem recurs for me. and I think i have problems with it
> because I just don't understand how Mathematica language works.
>
> 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?
>
> Maybe I'm asking a lot, but any and all insights are thoroughly
> appreciated.
>
> thanks in advance.
>
> sean
Prev by Date:
**Re: Question on pattern matching**
Next by Date:
**Re: FindRoot cannot find obvious solution**
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**
| |