0
$\begingroup$

Suppose I have an expression like Abs[x+I y]+Sin[Abs [c+ I (d+e)]],

and I want to replace all expressions in the form of Abs[a1 + I a2] to Sqrt[a1^2+a2^2].

How should I do that?

Thanks in advance!

$\endgroup$
1
$\begingroup$
expr = Abs[x + I y] + Sin[Abs[c + I (d + e)]];

expr /. Abs[a_ + I*b_] -> Sqrt[a^2 + b^2]

(*  Sqrt[x^2 + y^2] + Sin[Sqrt[c^2 + (d + e)^2]]  *)

Have fun!

$\endgroup$
4
$\begingroup$

Use ComplexExpand

expr = Abs[x + I y] + Sin[Abs[c + I (d + e)]];

expr // ComplexExpand

Sqrt[x^2 + y^2] + Sin[Sqrt[c^2 + (d + e)^2]]

$\endgroup$
  • 1
    $\begingroup$ It makes assumptions about symbols that are not necessarily in this form too. But as quick solution it is probably fine. $\endgroup$ – Kuba Apr 16 '15 at 7:35
  • 1
    $\begingroup$ @Kuba - the second argument to ComplexExpand is used to designate any variables in the expression that are complex. $\endgroup$ – Bob Hanlon Apr 16 '15 at 12:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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