# Finding Smooth Roots of a Function with log-term in the Upper Half-plane by Julia NLSolve

**URL:** <https://discourse.julialang.org/t/finding-smooth-roots-of-a-function-with-log-term-in-the-upper-half-plane-by-julia-nlsolve/98299>\
**Category:** New to Julia\
**Created:** [May 4, 2023, 6:33am UTC](https://discourse.julialang.org/t/finding-smooth-roots-of-a-function-with-log-term-in-the-upper-half-plane-by-julia-nlsolve/98299 "2023-05-04T06:33:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nek](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@Nek](https://discourse.julialang.org/u/Nek)\
**Post date:** [May 4, 2023, 6:33am UTC](https://discourse.julialang.org/t/finding-smooth-roots-of-a-function-with-log-term-in-the-upper-half-plane-by-julia-nlsolve/98299/1 "2023-05-04T06:33:34Z")

</div>

I am currently dealing with a complex function `F(z)` on the upper half-plane that has a log-term. I am trying to obtain its inverse function, but I can’t obtain its explicit form.

I used Julia package NLSolve and got `F^{-1}(w)` for each w in the complex plane by getting roots of `F(z) - w`, but there are some problems:

1. The roots are not smooth: I want roots to be smooth, but the results have some jumps and are not smooth due to branch cuts of the log-term. How can I set roots to be smooth by checking whether nearby points are mapped to nearby points or not?
2. Some roots are on the lower half-plane: `F(z)` is defined on the upper half-plane, but some roots are on the lower half-plane (maybe) due to the branch cut. How can I restrict the area of candidate roots in NLSolve?

---

<div class="post-metadata">

**Author:** ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)\
**Post date:** [May 4, 2023, 8:53am UTC](https://discourse.julialang.org/t/finding-smooth-roots-of-a-function-with-log-term-in-the-upper-half-plane-by-julia-nlsolve/98299/2 "2023-05-04T08:53:37Z")

</div>

Could you post your function?

---

<div class="post-metadata">

**Author:** ![sgaure](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sgaure/32/14779_2.png) [@sgaure](https://discourse.julialang.org/u/sgaure)\
**Post date:** [May 4, 2023, 11:36am UTC](https://discourse.julialang.org/t/finding-smooth-roots-of-a-function-with-log-term-in-the-upper-half-plane-by-julia-nlsolve/98299/3 "2023-05-04T11:36:58Z")

</div>

> [@Nek](#):
>
> Some roots are on the lower half-plane: `F(z)` is defined on the upper half-plane, but some roots are on the lower half-plane (maybe) due to the branch cut. How can I restrict the area of candidate roots in NLSolve?

If the domain is simple, as in this case, it’s usually simpler to transform into the domain rather than optimizing with a constraint. E.g. somthing like this:

```julia
transform(z) = Complex(real(z), imag(z)^2)
root = transform(solve(myfun ∘ transform))

```

Here the function `transform` maps into the upper half plane, so `myfun` is never evaluated outside. The solver may return something in the lower half plane, but the outer `transform` maps it to the right domain.

---

<div class="post-metadata">

**Author:** ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)\
**Post date:** [May 4, 2023, 12:55pm UTC](https://discourse.julialang.org/t/finding-smooth-roots-of-a-function-with-log-term-in-the-upper-half-plane-by-julia-nlsolve/98299/4 "2023-05-04T12:55:09Z")

</div>

I asked for the `myfun` expression, to deduce its properties: cut point(s), branch cuts… Their position might suggest how to find a local inverse.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [May 4, 2023, 2:02pm UTC](https://discourse.julialang.org/t/finding-smooth-roots-of-a-function-with-log-term-in-the-upper-half-plane-by-julia-nlsolve/98299/5 "2023-05-04T14:02:54Z")

</div>

Maybe use numerical continuation to get a “smooth” set of roots on a regular set of points in a region of the upper-half plane (e.g. at the simplest level, evaluate on a fine grid, but use the solution previous grid point as the starting guess for the nonlinear solve at the next grid point). If you evaluate at a grid of Chebyshev points you can then use [Chebyshev interpolation](https://github.com/stevengj/FastChebInterp.jl) to quickly and accurately interpolate from your grid to arbitrary w in this region.
