0
$\begingroup$

I have an expression as

$1 - 2 \sqrt{1 + i r} + i r$,

where $r$ is real.

I want to find the roots of its imaginary part. So:

Solve[Im[1 - 2 Sqrt[1 + I r] + I r] == 0, r, Reals]

However, Mathematica returns nothing. But by direct substitution in the expression $1 - 2 \sqrt{1 + i r} + i r$, for example for $r = 0.01$ one can see the imaginary part vanishes.

What's the problem here?

$\endgroup$
  • 1
    $\begingroup$ Try Solve[ComplexExpand[Im[1 - 2 Sqrt[1 + I r] + I r], TargetFunctions -> {Re, Im}] == 0, r, Reals] $\endgroup$ – J. M. will be back soon Oct 3 '18 at 17:00
  • $\begingroup$ Thanks. But it returns only $r = 0$. $\endgroup$ – user60516 Oct 3 '18 at 17:05
  • $\begingroup$ I don't think r=0.01 is a root. Look at: Plot[Im[1 - 2 Sqrt[1 + I r] + I r], {r, 0, 0.012}] $\endgroup$ – bill s Oct 3 '18 at 17:09
  • $\begingroup$ Yes. But the imaginary part is negligible to its real part when $r = 0.01$. $\endgroup$ – user60516 Oct 3 '18 at 17:11
  • 1
    $\begingroup$ "Negligible" only means small, and not always zero. You asked Mathematica for when it will exactly be zero, when you were interested in a different thing altogether. $\endgroup$ – J. M. will be back soon Oct 3 '18 at 17:20
3
$\begingroup$

Let's see what happens with your attempt:

Solve[Im[1 - 2 Sqrt[1 + I r] + I r] == 0, r, Reals]

Solve::nddc: The system -2 Im[Sqrt[1+I r]]+Re[r]==0 contains a nonreal constant I. With the domain \[DoubleStruckCapitalR] specified, all constants should be real.

Solve[-2 Im[Sqrt[1 + I r]] + Re[r] == 0, r, Reals]

Notice the error message. You can't use the domain Reals when the equation to be solved contains I. Instead, include the domain restriction along with your equation:

Solve[Im[1 - 2 Sqrt[1 + I r] + I r] == 0 && r ∈ Reals, r]

{{r -> 0}}

By the way, probably the most reliable method is the one suggested by @JM in the comments:

Solve[
    ComplexExpand[Im[1-2 Sqrt[1+I r]+I r], TargetFunctions->{Re, Im}] == 0,
    r,
    Reals
]

{{r -> 0}, {r -> 0}, {r -> 0}}

Addendum

In the comments, the OP explained that he wanted to know the values of r for which the imaginary part is negligible. Reduce is a better tool in this case. For example, the values of r for which the imaginary part is smaller in magnitude than 10^-6 can be obtained with:

Reduce[Abs @ Im[1-2 Sqrt[1+I r]+I r] < 10^-6 && r ∈ Reals, r] //N

-0.0200012 < r < 0.0200012

$\endgroup$

Your Answer

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