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.

Please read: make it easier to help you. 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.

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.

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.

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

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> 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]