MathGroup Archive 2009

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

Search the Archive

"mapping" functions over lists, again!

  • To: mathgroup at
  • Subject: [mg96199] "mapping" functions over lists, again!
  • From: "Paul Ellsmore" <paul.ellsmore at>
  • 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, =
now I realize that I didn=92t ask quite the question I thought I had, =
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 =
+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 =
+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 =
-0.0273182 =E4},{50.019,1699.76 -0.0491538 =E4},{53.888,1700.52 =
=E4},{58.057,1701.16 -0.242314 =E4}},{{40,1808.7 -0.00628662 =
-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 =
lists (four lists in the above case). I need to keep the integrity of =
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 =
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 =
+1.50876 =E4},{53.888,28.0573 +1.62452 =E4},{58.057,28.0565 +1.75026 =
=E4}} I get:


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:


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! =
have tried Map with Cases but frankly have no idea what the syntax =
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 =
simply not possible?

This is just a specific example of a difficulty I am having =
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 =
such as {real, complex} -> {real, f[real, complex]} but I just cannot =
out how to do this. Note that my datasets can be of varying length =96 =
is, the number of lists in shortTestdata can vary, and those lists will =
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.



Dr. Paul A. Ellsmore

Nanion Limited

Oxford Centre for Innovation

Mill Street


United Kingdom


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!