8
$\begingroup$

How can I flip the sign of the real part but not affect the imaginary part of a complex number:

a+bi => -a + bi

Example list:

list = {{-0.282095 + 0.282095 I, -0.27254 + 0.291336 I, 
-0.262018 + 0.300835 I, -0.250437 + 0.310542 I}}

expected:

{{0.282095 + 0.282095 I, 0.27254 + 0.291336 I, 
0.262018 + 0.300835 I, 0.250437 + 0.310542 I}}

So it's "similar" to conjugate but works on the real not imaginary.

$\endgroup$

3 Answers 3

30
$\begingroup$
-Conjugate[list]

(* {{0.282095 + 0.282095 I, 0.27254 + 0.291336 I, 
     0.262018 + 0.300835 I, 0.250437 + 0.310542 I}} *)
$\endgroup$
1
  • $\begingroup$ This is not even a Mathematica but a Math answer. I like it $\endgroup$ Oct 2, 2019 at 12:06
10
$\begingroup$
list /. Complex[x_, y_] :> Complex[-x, y]

{{0.282095 + 0.282095 I, 0.27254 + 0.291336 I, 0.262018 + 0.300835 I, 0.250437 + 0.310542 I, 2, 3 I}}

$\endgroup$
3
  • 1
    $\begingroup$ This assumes that all entries are truly Complex[_,_]. But for a list {{-0.282095 + 0.282095 I, -0.3445}}, which also contains only complex numbers (although one of them happens to be purely real, and even have Real head), this won't work correctly. $\endgroup$
    – Ruslan
    Oct 3, 2019 at 5:20
  • $\begingroup$ Agreed. This solution is for complex numbers of the form a + b i that was asked in the question. To include real numbers it needs to be modified to {Complex[x_,y_]:>Complex[-x,y], x_:>-x}. $\endgroup$ Oct 3, 2019 at 14:21
  • $\begingroup$ Actually this would also break for "complex" number like e.g. 1.234+0I, which actually collapses to a Real $\endgroup$
    – Ruslan
    Oct 3, 2019 at 14:23
2
$\begingroup$
f[z_] = -Re[z] + I Im[z]
f[list]

(* {{0.282095 + 0.282095 I, 0.27254 + 0.291336 I, 0.262018 + 0.300835 I, 0.250437 + 0.310542 I}} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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