# Solving F(X)=0 using nlsolve

I wanna solve a root finding problem of the form F(X)=0 using NLsolve.
However, I do not know the regularity of the function F, for example if it is not differentiable, so the Jacobian does not exists, how do the function nlsolve() work ? using a Newton method or a trust region method ?

You could use a bisection-style method, e.g. IntervalRootFinding.jl. In 1d, Roots.jl provides several methods.

(It looks like the algorithms in NLsolve.jl all assume differentiability?)

I tried for example f(x)=|x|, and it succeeded to converge even it is not differentiable at 0

I wouldnâ€™t count on it always working with a method that assumes differentiability.

|x| is a terrible function for root-finding with because it doesnâ€™t change sign when it crosses the root, something most algorithms assume. A function like that is probalby more suited for optimization (using non-smooth algorithms).

Of course, if you know the source of non-smoothness in your function, you should first try your hardest to remove the non-differentiability, e.g. by a change of variables or some other transformation. This will allow you to obtain faster convergence.

Thank you for your reply. In fact, using
nlsolve(F, [-5.0]; xtol=1e-8, method=:trust_region)
to determine the zero of F.

I m wondering if the nlsolve function have a regularization effet, or at least in the nondifferentiability point, it only uses finite differences instead of computing the Jacobian?

If an algorithm â€śat its heartâ€ť assumes that the function is differentiable, even if it doesnâ€™t compute derivatives explicitly (or approximates them in some way, e.g. by finite differences), then you should generally beware that it may not converge for non-differentiable functions.

Perhaps a better question is,why do you think your actual problem is non-smooth? (If you know it is non-smooth, then you may know enough to be able to derive some way to rectify the problem.)

1 Like

Thank you for your insight, itâ€™s better to consider the specific case of the function F and its properties (non-smoothness etc.)