# Is there a reliable package for solving simple equation system?

**URL:** https://discourse.julialang.org/t/is-there-a-reliable-package-for-solving-simple-equation-system/94877
**Category:** New to Julia
**Tags:** question, nlsolve, nonlinearsolve, linearsolve
**Created:** [February 19, 2023, 2:24pm UTC](https://discourse.julialang.org/t/is-there-a-reliable-package-for-solving-simple-equation-system/94877 "2023-02-19T14:24:20Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Kim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kim/32/46014_2.png) [@Kim](https://discourse.julialang.org/u/Kim)
#### Post date: [February 19, 2023, 2:24pm UTC](https://discourse.julialang.org/t/is-there-a-reliable-package-for-solving-simple-equation-system/94877/1 "2023-02-19T14:24:20Z")

</div>

Today I am working on finding the insections of a line and a infinite long cylinder. It is a simple math problem that can be solved by hand and very easy for Matlab. However, it looks like tough for Julia which is inspired by the so-called dissatisfactory Matlab. Given the equations of a 3-D line and a cylinder. I’ve tried several ways. Firstly, the Package HomotopyContinuation does not work for lines at some place and slope (e.g, a line from [47.8636, 0,0] to [49.3684,0,7.24951], and a 4 radius cylinder surrounding vector (0,1,0) and center on x=50, z=10). The Package NLsolver can only get one solution, while the proble definitely has two intersections. I searched a lot, but do not find a syntax to get all solutions . The SymPy is the third way I tried. There is still a obvious problem about the campability of SymPy on Julia. After I installed it, add or delete a space in code led to error. And for some very easy equations, it gave void solution (or no solution). Finally, I gave up and deduced the analytical solution by hand.

Welcome any helpful methods or suggestions for this basic and generic functionality.

---

<div class="post-metadata">

### Author: ![John\_Gibson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/john_gibson/32/5321_2.png) [@John\_Gibson](https://discourse.julialang.org/u/John_Gibson)
#### Post date: [February 19, 2023, 2:57pm UTC](https://discourse.julialang.org/t/is-there-a-reliable-package-for-solving-simple-equation-system/94877/2 "2023-02-19T14:57:03Z")

</div>

1. [Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757). It will help you get answers in this forum if you read this and follow its recommendations. For example, post code for a minimum working example rather than just describing your problem.
2. It’s too much to expect a nonlinear solver to find _all_ solutions. There is no upper bound on the number, location, narrowness, degree, etc of the roots of arbitrary nonlinear functions. Instead solvers typically find a single solution near a given initial guess. Try running NLSolver with an initial guess near the other solution.
3. Julia is sensitive to whitespace in a number of ways. You’ll need to provide more details (e.g. the code and where you changed whitespace) to get help on that.

---

<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: [February 19, 2023, 3:13pm UTC](https://discourse.julialang.org/t/is-there-a-reliable-package-for-solving-simple-equation-system/94877/3 "2023-02-19T15:13:15Z")

</div>

Did you try BifurcationKit.jl? That’s the one that is designed to give multiple solutions?

[https://bifurcationkit.github.io/BifurcationKitDocs.jl/dev/](https://bifurcationkit.github.io/BifurcationKitDocs.jl/dev/)

[https://bifurcationkit.github.io/BifurcationKitDocs.jl/dev/deflatedproblem/](https://bifurcationkit.github.io/BifurcationKitDocs.jl/dev/deflatedproblem/)

---

<div class="post-metadata">

### Author: ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)
#### Post date: [February 19, 2023, 5:10pm UTC](https://discourse.julialang.org/t/is-there-a-reliable-package-for-solving-simple-equation-system/94877/4 "2023-02-19T17:10:22Z")

</div>

I tried using this and it seems to work, at least for this simple example.

```julia
using HomotopyContinuation 
@var x y z; 
f = System([x^2 + y^2 - 4, y+z, x+z]) 
julia> f = System([x^2 + y^2 - 4, y+z, x+z]) 
System of length 3
 3 variables: x, y, z

 -4 + x^2 + y^2
 y + z
 x + z

julia> result = solve(f)
Result with 2 solutions
=======================
• 2 paths tracked
• 2 non-singular solutions (2 real)
• random_seed: 0xa63443f0
• start_system: :polyhedral

julia> s=real(solutions(result))
2-element Vector{Vector{Float64}}:
 [-1.4142135623730951, -1.4142135623730951, 1.4142135623730951]
 [1.414213562373095, 1.414213562373095, -1.414213562373095]

```

```julia
julia> f = System([x^2 + y^2 - 8, y+z, x+z]) # construct system f
System of length 3
 3 variables: x, y, z

 -8 + x^2 + y^2
 y + z
 x + z

julia> result = solve(f)
Result with 2 solutions
=======================
• 2 paths tracked
• 2 non-singular solutions (2 real)
• random_seed: 0x077e0c91
• start_system: :polyhedral

julia> s=real(solutions(result))
2-element Vector{Vector{Float64}}:
 [2.0, 2.0, -2.0]
 [-2.0, -2.0, 2.0]

julia> solutions(result)
2-element Vector{Vector{ComplexF64}}:
 [2.0 - 1.4349296274686127e-42im, 2.0 + 0.0im, -2.0 + 0.0im]
 [-2.0 + 0.0im, -2.0 + 0.0im, 2.0 + 0.0im]

```

---

<div class="post-metadata">

### Author: ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)
#### Post date: [February 19, 2023, 8:14pm UTC](https://discourse.julialang.org/t/is-there-a-reliable-package-for-solving-simple-equation-system/94877/5 "2023-02-19T20:14:20Z")

</div>

> [@Kim](#):
>
> Firstly, the Package HomotopyContinuation does not work for lines at some place and slope (e.g, a line from [47.8636, 0,0] to [49.3684,0,7.24951], and a 4 radius cylinder surrounding vector (0,1,0) and center on x=50, z=10).

```julia
julia> @var x y z; # declare the variables x, y and z

julia> A=[47.8636, 0,0]
3-element Vector{Float64}:
 47.8636
  0.0
  0.0

julia> B=[49.3684,0,7.24951]
3-element Vector{Float64}:
 49.3684
  0.0
  7.24951

julia> D=B.-A
3-element Vector{Float64}:
 1.504800000000003
 0.0
 7.24951

julia> f = System([(x-50)^2 + (z-10)^2 - 4,
       y, D[1]*z-D[3]*(x-A[1])])
System of length 3
 3 variables: x, y, z

 -4 + (-50 + x)^2 + (-10 + z)^2
 y
 1.5048*z - 7.24951*(-47.8636 + x)

julia> result = solve(f)
Result with 2 solutions
=======================
• 2 paths tracked
• 2 non-singular solutions (2 real)
• random_seed: 0xcdab3255
• start_system: :polyhedral

julia> real_solutions(result)
2-element Vector{Vector{Float64}}:
 [50.34813410654636, 0.0, 11.969467604165946]
 [49.53553132646704, 0.0, 8.054680270159523]

```
