[Date Index]
[Thread Index]
[Author Index]
"mapping" functions over lists, again!
*To*: mathgroup at smc.vnet.net
*Subject*: [mg96199] "mapping" functions over lists, again!
*From*: "Paul Ellsmore" <paul.ellsmore at nanion.co.uk>
*Date*: Mon, 9 Feb 2009 05:33:59 -0500 (EST)
I am a novice, and I have asked this question before (or tried to) and
thought that the answers I got would work, and that I understood them, =
but
now I realize that I didn=92t ask quite the question I thought I had, =
and
didn=92t understand the answers. So=85
I have data in the form:
shortTestdata = {{{40,28.0678 +1.20855 =E4},{43.094,28.0572 +1.29852
=E4},{46.428,28.0553 +1.40023 =E4},{50.019,28.0551 +1.50876 =
=E4},{53.888,28.0573
+1.62452 =E4},{58.057,28.0565 +1.75026 =E4}},{{40,7.42169 +0.219859
=E4},{43.094,7.4084 +0.234353 =E4},{46.428,7.40377 +0.252135 =
=E4},{50.019,7.40131
+0.271599 =E4},{53.888,7.40048 +0.292062 =E4},{58.057,7.39994 +0.314501
=E4}},{{40,1685.53 +0.0480998 =E4},{43.094,1694.69 -0.0913363 =
=E4},{46.428,1698.27
-0.0273182 =E4},{50.019,1699.76 -0.0491538 =E4},{53.888,1700.52 =
-0.217922
=E4},{58.057,1701.16 -0.242314 =E4}},{{40,1808.7 -0.00628662 =
=E4},{43.094,1808.52
-0.114076 =E4},{46.428,1808.53 -0.0244589 =E4},{50.019,1808.44 -0.106166
=E4},{53.888,1808.48 -0.176297 =E4},{58.057,1808.63 -0.289451 =E4}}} =
that is to
say, lists of pairs of real and complex values. Note that I mean a list =
of
lists (four lists in the above case). I need to keep the integrity of =
these
lists, while doing operations on them.
In particular, I want to be able to turn every pair {real, complex} into
{real, f[complex]}. It was suggested to me that I use Cases, as follows:
Realpart = Cases[shortTestdata,{r_Real,c_Complex}=A6{r,Re[c]}] . If I =
apply
this to the first list in shortTestdata, i.e {{40,28.0678 +1.20855
=E4},{43.094,28.0572 +1.29852 =E4},{46.428,28.0553 +1.40023 =
=E4},{50.019,28.0551
+1.50876 =E4},{53.888,28.0573 +1.62452 =E4},{58.057,28.0565 +1.75026 =
=E4}} I get:
{{43.094,28.0572},{46.428,28.0553},{50.019,28.0551},{53.888,28.0573},{58.=
057
,28.0565}}
This seems to miss out the first data pair of the list. Am I making a
mistake with the syntax?
I thought that the following would work for the full lists of lists:
realpart=Cases[shortTestdata,{r_Real,c_Complex}=A6{r,Re[c]},2] i.e =
apply the
rule to all parts at level 2 of shortTestdata, but I get:
{{43.094,28.0572},{46.428,28.0553},{50.019,28.0551},{53.888,28.0573},{58.=
057
,28.0565},{43.094,7.4084},{46.428,7.40377},{50.019,7.40131},{53.888,7.400=
48}
,{58.057,7.39994},{43.094,1694.69},{46.428,1698.27},{50.019,1699.76},{53.=
888
,1700.52},{58.057,1701.16},{43.094,1808.52},{46.428,1808.53},{50.019,1808=
.44
},{53.888,1808.48},{58.057,1808.63}}
This still misses the first pair of each list, and now flattens the
structure, so I don=92t know where my four lists start and end any more! =
I
have tried Map with Cases but frankly have no idea what the syntax =
should
look like, and either get error messages or empty lists as output. The
documentation shows no examples of Map on a list of lists, so maybe it =
is
simply not possible?
This is just a specific example of a difficulty I am having =
understanding
how Mathematica deals with lists of lists. In general I would like to be
able to =93Map=94 functions over these lists of lists, to make =
transformations
such as {real, complex} -> {real, f[real, complex]} but I just cannot =
figure
out how to do this. Note that my datasets can be of varying length =96 =
that
is, the number of lists in shortTestdata can vary, and those lists will =
not
in general be all of the same length, so Flatten and Partition are not
convenient to use, and I really do need the list of lists structure.
Any help would be very gratefully received.
Thanks,
Paul.
Dr. Paul A. Ellsmore
Nanion Limited
Oxford Centre for Innovation
Mill Street
Oxford
United Kingdom
OX2 0JX
Tel: +44 (0) 1865 811175
Fax: +44 (0) 1865 248594
Prev by Date:
**Re: How to simplify?**
Next by Date:
**Re: Re: Re: Re: Re: Log[x]//TraditionalForm**
Previous by thread:
**Titles/Labels in Graphics**
Next by thread:
**Re: "mapping" functions over lists, again!**
| |