# Solving nonlinear equations using inexact Newton — seeking recommendations

**URL:** <https://discourse.julialang.org/t/solving-nonlinear-equations-using-inexact-newton-seeking-recommendations/119887>\
**Category:** General Usage\
**Tags:** question, nonlinear\
**Created:** [September 26, 2024, 1:24am UTC](https://discourse.julialang.org/t/solving-nonlinear-equations-using-inexact-newton-seeking-recommendations/119887 "2024-09-26T01:24:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mpf01](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mpf01/32/8221_2.png) [@mpf01](https://discourse.julialang.org/u/mpf01)\
**Post date:** [September 26, 2024, 1:24am UTC](https://discourse.julialang.org/t/solving-nonlinear-equations-using-inexact-newton-seeking-recommendations/119887/1 "2024-09-26T01:24:31Z")

</div>

I’m seeking recommendations for a package for solving a large system of nonlinear equations, allowing for inexact Newton system solves using iterative linear solvers. My Jacobian is symmetric indefinite, and so I hope to use Minres as the linear solver.

Here are a couple of options I’ve explored:

- `trunkls` in [JSOSolvers.jl](https://github.com/JuliaSmoothOptimizers/JSOSolvers.jl) is really good. However, it lacks support for symmetric linear solvers, which leads to doubling the number of Jacobian-vector products.
- `NonlinearSolve.jl` allows for a variety of linear solvers, but it doesn’t appear to have built-in support for inexact solves. Modifying the package may not be straightforward.

I’d appreciate any suggestions on other packages that might be suitable.

Thank you!  
Michael

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [September 26, 2024, 7:41am UTC](https://discourse.julialang.org/t/solving-nonlinear-equations-using-inexact-newton-seeking-recommendations/119887/2 "2024-09-26T07:41:41Z")

</div>

> [@mpf01](#):
>
> - `NonlinearSolve.jl` allows for a variety of linear solvers, but it doesn’t appear to have built-in support for inexact solves. Modifying the package may not be straightforward.

Should be fine to add this in there. What exactly is missing?

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [September 26, 2024, 10:57am UTC](https://discourse.julialang.org/t/solving-nonlinear-equations-using-inexact-newton-seeking-recommendations/119887/3 "2024-09-26T10:57:23Z")

</div>

I would imagine @ctkelley might have some ideas?

---

<div class="post-metadata">

**Author:** ![photor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/photor/32/14343_2.png) [@photor](https://discourse.julialang.org/u/photor)\
**Post date:** [September 26, 2024, 11:03am UTC](https://discourse.julialang.org/t/solving-nonlinear-equations-using-inexact-newton-seeking-recommendations/119887/4 "2024-09-26T11:03:20Z")

</div>

This might also be useful for me 😜

---

<div class="post-metadata">

**Author:** ![mpf01](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mpf01/32/8221_2.png) [@mpf01](https://discourse.julialang.org/u/mpf01)\
**Post date:** [September 26, 2024, 6:36pm UTC](https://discourse.julialang.org/t/solving-nonlinear-equations-using-inexact-newton-seeking-recommendations/119887/5 "2024-09-26T18:36:00Z")

</div>

Inexact Newton relies on a forcing sequence \eta\_k\in(0,1) that defines the accuracy of each linear subsolve, ie,

\|r(x\_k)+J(x\_k)\Delta x\_k\|\le\eta\_k\|r(x\_k)\|,

where r(x\_k) is th residual at the k-th Newton iteration and J is its Jacobian.

Currently, NonlinearSolve.jl only allows for a fixed \eta\_k=\eta, specified through the `linsolve` keyword, eg,

```julia
solve(prob, NewtonRaphson(linsolve=KrylovJL_MINRES(rtol=η))

```

I’m hoping for a way to set the per-iteration accuracy. I tried using the [iterator interface](https://docs.sciml.ai/NonlinearSolve/stable/tutorials/iterator_interface/)

```julia
for i in 1:10
    step!(nlcache)
end

```

with the idea that I could query `nlcache` for the current residual in order to define the next value of `rtol=`\eta\_k. I can see that `rtol` is buried somewhere inside `nlcache`. Is there a way to change it?

---

<div class="post-metadata">

**Author:** ![ctkelley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ctkelley/32/10684_2.png) [@ctkelley](https://discourse.julialang.org/u/ctkelley)\
**Post date:** [September 26, 2024, 7:37pm UTC](https://discourse.julialang.org/t/solving-nonlinear-equations-using-inexact-newton-seeking-recommendations/119887/6 "2024-09-26T19:37:51Z")

</div>

The `nsoli.jl` solver in my package [SIAMFANLEquations.jl](https://github.com/ctkelley/SIAMFANLEquations.jl) has matrix free inexact Newton methods. These are pretty well documented in a [book](https://epubs.siam.org/doi/book/10.1137/1.9781611977271) and a suite of [Jupyter Notebooks](https://github.com/ctkelley/NotebookSIAMFANL) with examples and explanations of the methods. I support GMRES(m) and BICGSTAB, but not Minres. You have access to the forcing term \eta and other algorithmic parameters.

The API is not like NonlinearSolve.jl because the package was designed to support a book project and I wanted all the algorithmic parameters to be easy to play with. I think [NonlinearSolve.jl](https://docs.sciml.ai/NonlinearSolve/stable/) will let you get to [SIAMFANLEquations.jl](https://github.com/ctkelley/SIAMFANLEquations.jl) as you can see by scrolling to the bottom of [this page](https://docs.sciml.ai/NonlinearSolve/stable/solvers/nonlinear_system_solvers/#nonlinearsystemsolvers). I have not played with this and do not know how easy it is to use.
