MathGroup Archive 2009

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

Search the Archive

Problem Solved! - FW: Reposted, Reformatted Re: "mapping" functions over lists, again

  • To: mathgroup at smc.vnet.net
  • Subject: [mg96342] Problem Solved! - FW: Reposted, Reformatted Re: "mapping" functions over lists, again
  • From: "Paul Ellsmore" <paul.ellsmore at nanion.co.uk>
  • Date: Thu, 12 Feb 2009 06:33:45 -0500 (EST)

Thanks to all who contributed - I now have a very good solution for my
particular situation. My data sets are simple and consistent enough to just
use the replacement operator rather than Map or Cases or anything more
complicated.

BTW - although I took great care with this latest post, it still acquired
some spurious " = " symbols where some linewraps should have been, and I
have noticed these on other posts as well. I used Notepad to compose the
post, was careful to convert to InputForm before copying and pasting from
Mathematica, and then cut and pasted the Notepad content into Outlook. Is
there anything more I could have done, or is Outlook not friendly to the
Mathgroup server?

Cheers again,

Paul.

-----Original Message-----
From: Jean-Marc Gulliet [mailto:jeanmarc.gulliet at gmail.com] 
Sent: 11 February 2009 12:22
To: Paul Ellsmore
Subject: [mg96342] Re: Reposted, Reformatted Re: "mapping" functions over lists,
again!

In article <gmu8ik$geb$1 at smc.vnet.net>,
 "Paul Ellsmore" <paul.ellsmore at nanion.co.uk> wrote:

> This is a repost of an earlier post, as there were problems with the =
> email
> formatting for some people. I have composed this one in Notepad, and cut =
> and
> pasted to Outlook. Hope it works better.

You should try to copy and past Mathematica expressions in InputForm[], 
for it is way more readable and far less prone to misinterpretation 
(especially when your email/newsgroup client adds spurious equal sings 
and/or other unwanted characters or character conversions).

To use the _InputForm_ when copying an expression from a Mathematica 
notebook to an email client: select the cell(s) you want to include in 
your email, then within the *Cell* menu select either *Convert To* or 
*Display As* and choose *InputForm*. Finally, copy and paste as usual.
 
> Thanks to all who have already given me some advice, but I still haven't
> quite got it yet!
> 
>  My data is in the form:
> 
> shortTestdata = {{{40., 28.06776 + 1.208548*I}, {43.094, 28.05721 +
> 1.298519*I}, {46.428, 28.05527 + 1.400228*I}, {50.019, 28.05509 +
> 1.508759*I},
>     {53.888, 28.05729 + 1.624517*I}, {58.057, 28.05651 + 1.75026*I}}, =
> {{40.,
> 7.42169 + 0.2198589*I}, {43.094, 7.408397 + 0.2343525*I},
>     {46.428, 7.403769 + 0.2521353*I}, {50.019, 7.401313 + 0.2715986*I},
> {53.888, 7.400478 + 0.2920617*I}, {58.057, 7.39994 + 0.3145005*I}},
>    {{40., 1685.526 + 0.04809976*I}, {43.094, 1694.691 - 0.09133625*I},
> {46.428, 1698.265 - 0.02731824*I}, {50.019, 1699.761 - 0.0491538*I},
>     {53.888, 1700.523 - 0.2179222*I}, {58.057, 1701.162 - 0.2423136*I}},
> {{40., 1808.702 - 0.006286621*I}, {43.094, 1808.524 - 0.1140757*I},
>     {46.428, 1808.534 - 0.02445889*I}, {50.019, 1808.443 - 0.1061664*I},
> {53.888, 1808.481 - 0.1762974*I}, {58.057, 1808.631 - 0.2894506*I}}}
> 
> This is a list of lists, the lowest level lists containing pairs of =
> {real,
> complex}. The individual lists are not all the same length, and the =
> total
> number of lists can vary, and I need to preserve the list structure.

[snip]

I suggest to use the replacement operator "/." (w/o the quotation marks) 
to apply the transformation rule. In doing so, the structure of the 
original list will be preserved. Therfore, rather than Cases[] or Map[], 
you could use

    shortTestdata /. {r_Real, c_Complex} :> {r, Re[c]}

For instance, here is a complete example applied to your data:

In[1]:= shortTestdata = {{{40., 28.06776 + 1.208548*I}, {43.094, 
     28.05721 + 1.298519*I}, {46.428, 28.05527 + 1.400228*I}, {50.019,
      28.05509 + 1.508759*I}, {53.888, 
     28.05729 + 1.624517*I}, {58.057, 28.05651 + 1.75026*I}}, {{40., 
     7.42169 + 0.2198589*I}, {43.094, 
     7.408397 + 0.2343525*I}, {46.428, 
     7.403769 + 0.2521353*I}, {50.019, 
     7.401313 + 0.2715986*I}, {53.888, 
     7.400478 + 0.2920617*I}, {58.057, 7.39994 + 0.3145005*I}}, {{40.,
      1685.526 + 0.04809976*I}, {43.094, 
     1694.691 - 0.09133625*I}, {46.428, 
     1698.265 - 0.02731824*I}, {50.019, 
     1699.761 - 0.0491538*I}, {53.888, 
     1700.523 - 0.2179222*I}, {58.057, 
     1701.162 - 0.2423136*I}}, {{40., 
     1808.702 - 0.006286621*I}, {43.094, 
     1808.524 - 0.1140757*I}, {46.428, 
     1808.534 - 0.02445889*I}, {50.019, 
     1808.443 - 0.1061664*I}, {53.888, 
     1808.481 - 0.1762974*I}, {58.057, 1808.631 - 0.2894506*I}}};

In[2]:= Dimensions[shortTestdata]

Out[2]= {4, 6, 2}

In[3]:= lst = shortTestdata /. {r_Real, c_Complex} :> {r, Re[c]}

Out[3]= {{{40., 28.0678}, {43.094, 28.0572}, {46.428, 
   28.0553}, {50.019, 28.0551}, {53.888, 28.0573}, {58.057, 
   28.0565}}, {{40., 7.42169}, {43.094, 7.4084}, {46.428, 
   7.40377}, {50.019, 7.40131}, {53.888, 7.40048}, {58.057, 
   7.39994}}, {{40., 1685.53}, {43.094, 1694.69}, {46.428, 
   1698.27}, {50.019, 1699.76}, {53.888, 1700.52}, {58.057, 
   1701.16}}, {{40., 1808.7}, {43.094, 1808.52}, {46.428, 
   1808.53}, {50.019, 1808.44}, {53.888, 1808.48}, {58.057, 
   1808.63}}}

In[4]:= Dimensions[lst]

Out[4]= {4, 6, 2}

HTH,
--Jean-Marc



  • Prev by Date: Re: Re: Log[x]//TraditionalForm
  • Next by Date: Re: weather blog and ListStreamPlot sampling
  • Previous by thread: internal details of Options, Default, Attributes
  • Next by thread: New free introductory book on Mathematica programming, and a few