Symbolically solve a linear system of equations

Dear all,

I am trying to symbolically solve a system of equation with Julia. I have spent some time in the LinearAlgebra.jl documentation and in the Symbolics.jl documentation. I have also searched (quite) a bit in the internet, but I was not able to find a satisfactory answer to my questions. I should also say that I am quite new to Julia and not an expert at programming in general, so I apologize in advance if I am asking obvious questions.

My situation is the following.
I have a matrix with real (actually they are integer) entries, for the sake of concreteness let’s take the following:

A = [ [ 1 0 ]
       [ 0 0 ] ]

and I have a vector of variables, for the sake of concreteness let’s take

x = [x1,x2]

I would like to write something like

solve A x = 0

and get an answer of the kind

vector space generated by the vector [0,1]

or an answer of the kind


which I would interpret as “every vector whose first component is 0 is a solution of the linear system, no matter which is the value of the second variable”.

In trying to do this I have managed to use Symbolics.jl to write my vector of variables and my system of equations. However, if the matrix is singular (as in the example I am making here), then I just get an error. How do I work around this?

I would also be fine with some solution in which I transform my original matrix in pivot form, solve the system for the nonsingular pivot form for some new variables and then get back the original variables by having kept track of the transformations made to get to the pivot form, but I did not manage to find a way to do this automatically.

For better reference, here is a sample of the code I have so far:

using  LinearAlgebra, Symbolics,LinearSolve
A = [[1 0]
	 [0 0]]
@variables x1 x2
x = [x1, x2]
c=A * x
eqs = [c[i]~0.0 for i ∈ 1:2]

Please also note that I am not used to write in forums. I tried to read the rules and I hope I got everything right from this point of view.

I would be very grateful for any kind of help you could provide.

1 Like

I do not know how, but I missed the function


from the LinearAlgebra standard library. Maybe it is not exactly what I was asking for, but I do not think I would have ever asked the question if I had found it before. I will thus mark this answer as a solution.

There is also


from the Nemo.jl package.

Anyway, maybe it is cleaner for the forum to delete the whole topic (I do not have the permission to do so…)

1 Like