# Julia equivalent for python scipy.optimize.fsolve

**URL:** <https://discourse.julialang.org/t/julia-equivalent-for-python-scipy-optimize-fsolve/46139>\
**Category:** General Usage\
**Tags:** package, roots\
**Created:** [September 6, 2020, 12:09pm UTC](https://discourse.julialang.org/t/julia-equivalent-for-python-scipy-optimize-fsolve/46139 "2020-09-06T12:09:12Z")\
**Posts on this page:** 1\
**Showing post:** 5

<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:** [September 6, 2020, 12:54pm UTC](https://discourse.julialang.org/t/julia-equivalent-for-python-scipy-optimize-fsolve/46139/5 "2020-09-06T12:54:56Z")

</div>

> [@HerAdri](#):
>
> What would be the Julia equivalent for python scipy.optimize.fsolve

There a several options, I think, but the [NLsolve.jl package](https://github.com/JuliaNLSolvers/NLsolve.jl) is one possibility:

```julia
julia> using NLsolve

julia> function F!(F, x)
         F[1] = 1 - x[1] - x[2]
         F[2] = 8 - x[1] - 3x[2]
       end

julia> result = nlsolve(F!, [1.0,1.0], autodiff=:forward)
Results of Nonlinear Solver Algorithm
 * Algorithm: Trust-region with dogleg and autoscaling
 * Starting Point: [1.0, 1.0]
 * Zero: [-2.5, 3.5]
 * Inf-norm of residuals: 0.000000
 * Iterations: 2
 * Convergence: true
   * |x - x'| < 0.0e+00: false
   * |f(x)| < 1.0e-08: true
 * Function Calls (f): 3
 * Jacobian Calls (df/dx): 3

julia> result.zero
2-element Vector{Float64}:
 -2.5
  3.5

```

Of course, if you _know_ that your equations are linear, you should really put them into some kind of matrix and use `\`:

```julia
julia> [1 1; 1 3] \ [1, 8]
2-element Vector{Float64}:
 -2.5
  3.5

```

but perhaps your real problem is nonlinear and you intended this `F` as a toy problem to figure out the library?

---

_[View the full topic](https://discourse.julialang.org/t/julia-equivalent-for-python-scipy-optimize-fsolve/46139)._
