0

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!

Karsten7
  • 27,448
  • 5
  • 73
  • 134
username123
  • 257
  • 1
  • 6

2 Answers2

4

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]]

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
  • 1
    It makes assumptions about symbols that are not necessarily in this form too. But as quick solution it is probably fine. – Kuba Apr 16 '15 at 07:35
  • 1
    @Kuba - the second argument to ComplexExpand is used to designate any variables in the expression that are complex. – Bob Hanlon Apr 16 '15 at 12:38
1
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!

Alexei Boulbitch
  • 39,397
  • 2
  • 47
  • 96