Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Let's say I have this list of solutions from a previous computation:

{
 {x -> -9.640491283722653` - 5.790987589334252` I}, 
 {x -> -9.640491283722653` + 5.790987589334252` I},
 {x ->  0.`- 14.792128645445802` I},
 {x ->  0.`+ 14.792128645445802` I},
 {x ->  9.640491283722653`- 5.790987589334252` I},
 {x ->  9.640491283722653`+ 5.790987589334252` I}
}

Now, how do I extract a list of coordinates from them?

Like

{
 {-9.640491283722653`, - 5.790987589334252`},
 {-9.640491283722653`, + 5.790987589334252`},
 {0.`,- 14.792128645445802`},
 {0.`,+ 14.792128645445802},
 {9.640491283722653`,- 5.790987589334252`},
 {9.640491283722653`,+ 5.790987589334252` }
}
share|improve this question
add comment

2 Answers 2

up vote 4 down vote accepted

Works nicely:

rules = {{x -> -9.640491283722653` - 5.790987589334252` I},
         {x -> -9.640491283722653` + 5.790987589334252` I},
         {x -> 0.` - 14.792128645445802` I}, {x -> 0.` + 14.792128645445802` I},
         {x -> 9.640491283722653` - 5.790987589334252` I},
         {x -> 9.640491283722653` + 5.790987589334252` I}};

Through[{Re, Im}[x]] /. rules
   {{-9.64049, -5.79099}, {-9.64049, 5.79099}, {0., -14.7921}, {0., 14.7921},
    {9.64049, -5.79099}, {9.64049, 5.79099}}
share|improve this answer
    
/. is a shortcut for which function ? –  The-Ever-Kid Nov 24 '12 at 4:55
1  
@The-Ever-Kid, in the interest of teaching you how to fish: highlight the /. in your Mathematica notebook and press F1. –  J. M. Nov 24 '12 at 4:56
    
Thanks.....BTW you learned all you know from the Docs Right ? –  The-Ever-Kid Nov 24 '12 at 4:58
2  
...and reading other resources, and a lot of practice and trial and error. –  J. M. Nov 24 '12 at 4:59
add comment

J. M. recommended: Through[{Re, Im}[x]] /. rules

I believe it is cleaner to use: {Re@x, Im@x} /. rules

These prove to be equivalent.

First an explanation of the replacement being done (with /.). As shown in the documentation when the right-hand side of /. is a list of lists of rules you get replacements for each:

x /. {{x -> 1}, {x -> 3}, {x -> 7}}
{1, 3, 7}

ReplaceAll (the long form of /.) does not have a Hold attribute so Through[{Re, Im}[x]] actually evaluates to {Re[x], Im[x]} before the replacements are made. (I use @ simply because I like to save keystrokes and reduce stacking of brackets.)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.