# Nlsolver vs Matlab fsolve

**URL:** <https://discourse.julialang.org/t/nlsolver-vs-matlab-fsolve/119523>\
**Category:** Optimization (Mathematical)\
**Tags:** question\
**Created:** [September 17, 2024, 8:06pm UTC](https://discourse.julialang.org/t/nlsolver-vs-matlab-fsolve/119523 "2024-09-17T20:06:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![w17n2411](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/w17n2411/32/214407_2.png) [@w17n2411](https://discourse.julialang.org/u/w17n2411)\
**Post date:** [September 17, 2024, 8:06pm UTC](https://discourse.julialang.org/t/nlsolver-vs-matlab-fsolve/119523/1 "2024-09-17T20:06:19Z")

</div>

I have some code to solve a system of nonlinear equations given some state variables (both in Matlab and Julia). The solution is quite sensitive and I have to use homotopy to solve it for a variety of points in the state space. Matlab using fsolve runs fast and solves all of the cases except for some extreme examples. Julia’s nlsolver crashs for many more of the points in the state space. I am just running the solvers on their baseline settings. Is there a solver in Julia which can reproduce Matlab’s restults with fsolve?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [September 17, 2024, 8:14pm UTC](https://discourse.julialang.org/t/nlsolver-vs-matlab-fsolve/119523/2 "2024-09-17T20:14:49Z")

</div>

What do you mean by Julia’s `Nlsolver`? IMO the best nonlinear solver in julia is NonlinearSolve.jl. is that one of the options you have tried?

---

<div class="post-metadata">

**Author:** ![w17n2411](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/w17n2411/32/214407_2.png) [@w17n2411](https://discourse.julialang.org/u/w17n2411)\
**Post date:** [September 17, 2024, 8:25pm UTC](https://discourse.julialang.org/t/nlsolver-vs-matlab-fsolve/119523/3 "2024-09-17T20:25:08Z")

</div>

Thanks for replying. I noticed similar posts from some time ago, but they did not have any good resolution. Here is what I did:

using NLsolve

nlsolve(…)

So this is what I have used, which is what comes up when I query Google. Interestingly, I first wrote this basic code 5 years ago and the current version of Matlab fsolve runs much better now than it did. So something has changed on their end.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [September 17, 2024, 8:52pm UTC](https://discourse.julialang.org/t/nlsolver-vs-matlab-fsolve/119523/4 "2024-09-17T20:52:42Z")

</div>

> [@w17n2411](#):
>
> using NLsolve

So you did not try NonlinearSolve, which is a different package than NLsolve. Can you give it a try?

Or share the code that does not work well with Julia.

---

<div class="post-metadata">

**Author:** ![w17n2411](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/w17n2411/32/214407_2.png) [@w17n2411](https://discourse.julialang.org/u/w17n2411)\
**Post date:** [September 17, 2024, 8:54pm UTC](https://discourse.julialang.org/t/nlsolver-vs-matlab-fsolve/119523/5 "2024-09-17T20:54:21Z")

</div>

> [@ufechner7](#):
>
> NonlinearSolve

Let me try that. I just googled it and got a github page. I’ll try and find some sort of tutorial or readme and see if that works. Thanks for the suggestion.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [September 17, 2024, 8:55pm UTC](https://discourse.julialang.org/t/nlsolver-vs-matlab-fsolve/119523/6 "2024-09-17T20:55:44Z")

</div>

> [@w17n2411](#):
>
> I’ll try and find some sort of tutorial or readme

Just use the official documentation: [NonlinearSolve.jl: High-Performance Unified Nonlinear Solvers · NonlinearSolve.jl](https://docs.sciml.ai/NonlinearSolve/stable/)

---

<div class="post-metadata">

**Author:** ![w17n2411](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/w17n2411/32/214407_2.png) [@w17n2411](https://discourse.julialang.org/u/w17n2411)\
**Post date:** [September 17, 2024, 9:03pm UTC](https://discourse.julialang.org/t/nlsolver-vs-matlab-fsolve/119523/7 "2024-09-17T21:03:37Z")

</div>

Will do. I ran the same code and it worked. Now I’ll go back to what I was doing and see if it will work too. Thanks very much for your help.
