I’m using SymPy in Julia to solve a system of equations and I would like to be able to call the SymPy function linear_eq_to_matrix as documented on this page: http://docs.sympy.org/latest/modules/solvers/solveset.html
I have a Python script containing the following code that uses the function:
#!/usr/local/bin/python
from sympy import *
x, y, z = symbols('x y z')
eqns = [x + 2*y + 3*z - 1, 3*x + y + z + 6, 2*x + 4*y + 9*z - 2]
print("eqns = ", eqns)
A, b = linear_eq_to_matrix(eqns, [x, y, z])
print("A = ", A)
print("b = ", b)
When I run this, I get the expected output:
eqns = [x + 2*y + 3*z - 1, 3*x + y + z + 6, 2*x + 4*y + 9*z - 2]
A = Matrix([[1, 2, 3], [3, 1, 1], [2, 4, 9]])
b = Matrix([[1], [-6], [2]])
Now, when I try to do the same thing in Julia, I have tried the following input file:
#!/usr/local/bin/julia
using SymPy
@vars x y z
eqns = ([x + 2*y + 3*z - 1, 3*x + y + z + 6, 2*x + 4*y + 9*z - 2])
println("eqns = ", eqns)
A, b = linear_eq_to_matrix(eqns, ([x, y, z]))
println("A = ", A)
println("b = ", b)
But this fails with the following output/error:
eqns = SymPy.Sym[x + 2*y + 3*z - 1, 3*x + y + z + 6, 2*x + 4*y + 9*z - 2]
ERROR: LoadError: UndefVarError: linear_eq_to_matrix not defined
Stacktrace:
[1] include_from_node1(::String) at ./loading.jl:569
[2] include(::String) at ./sysimg.jl:14
[3] process_options(::Base.JLOptions) at ./client.jl:305
[4] _start() at ./client.jl:371
while loading /...path_to_my_file.../juliaTest.jl, in expression starting on line 10
I have tried to figure out how to use PyCall or something similar to directly call this function but with no success. I have confirmed that I am calling/using the same versions of Python/SymPy in Julia so that’s not the issue. I have also confirmed that the SymPy function “solveset” which is documented on the link I provided above does work as expected in both Julia and Python, so it seems like Julia should be able to call “linear_eq_to_matrix” somehow, even if it’s a bit clunky.
Can someone please show me how to do this? Thanks.