# How to use different solver of NonlinearSolve.jl?

**URL:** <https://discourse.julialang.org/t/how-to-use-different-solver-of-nonlinearsolve-jl/102547>\
**Category:** New to Julia\
**Created:** [August 7, 2023, 6:00am UTC](https://discourse.julialang.org/t/how-to-use-different-solver-of-nonlinearsolve-jl/102547 "2023-08-07T06:00:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![baizhan](https://avatars.discourse-cdn.com/v4/letter/b/ecae2f/32.png) [@baizhan](https://discourse.julialang.org/u/baizhan)\
**Post date:** [August 7, 2023, 6:00am UTC](https://discourse.julialang.org/t/how-to-use-different-solver-of-nonlinearsolve-jl/102547/1 "2023-08-07T06:00:07Z")

</div>

I am using NonlinearSolve but have some stupid problem.

I can run the following example script:

```julia
using NonlinearSolve, StaticArrays

f(u, p) = u .* u .- p
u0 = @SVector[1.0, 1.0]
p = 2.0
probN = NonlinearProblem(f, u0, p)
sol = solve(probN, NewtonRaphson(), reltol = 1e-9)

```

However, when I want to use other methods, for example the trust-region method or the Broyden method, I simply change the last line to

```julia
sol = solve(probN, TrustRegion(), reltol = 1e-9)

```

or

```julia
sol = solve(probN, Broyden(), reltol = 1e-9)

```

But the REPL simply tells me that neither Trustregion nor Broyden is defined.  
Why is that and How can I use these methods?

Also, the example code only works if `u0` is static. What can I do if I want to use normal (non-static) array?

---

<div class="post-metadata">

**Author:** ![mike\_k](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike_k/32/211864_2.png) [@mike\_k](https://discourse.julialang.org/u/mike_k)\
**Post date:** [August 7, 2023, 12:13pm UTC](https://discourse.julialang.org/t/how-to-use-different-solver-of-nonlinearsolve-jl/102547/2 "2023-08-07T12:13:35Z")

</div>

The [documentation](https://docs.sciml.ai/NonlinearSolve/stable/solvers/NonlinearSystemSolvers/) says that `Broyden()` is included, however, maybe you also need [SimpleNonlinearSolve](https://github.com/SciML/SimpleNonlinearSolve.jl). You could try to install the latter package, and to add it to your code. Regarding `TrustRegion()`, I have no clue. EDIT: it is written in the docs that `TrustRegion()` is still in development.

---

<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:** [August 7, 2023, 12:37pm UTC](https://discourse.julialang.org/t/how-to-use-different-solver-of-nonlinearsolve-jl/102547/3 "2023-08-07T12:37:34Z")

</div>

What version do you have? Those should just work.

---

<div class="post-metadata">

**Author:** ![baizhan](https://avatars.discourse-cdn.com/v4/letter/b/ecae2f/32.png) [@baizhan](https://discourse.julialang.org/u/baizhan)\
**Post date:** [August 8, 2023, 7:20am UTC](https://discourse.julialang.org/t/how-to-use-different-solver-of-nonlinearsolve-jl/102547/4 "2023-08-08T07:20:17Z")

</div>

Thank you!  
After adding `using SimpleNonlinearSolve`, the broyden method works.

---

<div class="post-metadata">

**Author:** ![mike\_k](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike_k/32/211864_2.png) [@mike\_k](https://discourse.julialang.org/u/mike_k)\
**Post date:** [August 8, 2023, 8:13am UTC](https://discourse.julialang.org/t/how-to-use-different-solver-of-nonlinearsolve-jl/102547/5 "2023-08-08T08:13:07Z")

</div>

Great. Btw.: you are more likely to get help on such topics, if you post them in the category `Optimization (Mathematical)`.
