 Anonymous

Hi. Why is no kernel found for the 2x3 matrix A=[2,3,5];[-4,2,3] ?

sage: A = matrix([[2,3,5],[-4,2,3]])
sage: A
[ 2  3  5]
[-4  2  3]
sage: A.kernel()
Free module of degree 2 and rank 0 over Integer Ring
Echelon basis matrix:
[]


However we know that the kernel should be given by: x=-z/16 and y=-13z/8

edit retag close merge delete

Sort by » oldest newest most voted Sage returns the left kernel. This is written in the documentation that you can access by

sage: A.kernel?


You want the right kernel:

sage: A.right_kernel()

more

While A.right_kernel() returns [ 1 26 -16], it's only one possible solution from the solution set. Instead, I expect it to return c * [ 1 26 -16 ]. Any idea how to not miss out all the solutions?

What A.right_kernel() returns is not a vector but a module with basis. (If you create a matrix over a field like A = matrix(QQ, [[2,3,5],[-4,2,3]]) it returns a vector space with basis.) You can obtain the basis (which is a sequence of vectors) by b = A.right_kernel().basis(). The set of solutions to $Ax = 0$ is spanned by this basis, i.e. all solutions are linear combinations of those basis vectors. If you insist, you can introduce the appropriate number of symbolic variables c = [var('c_%d' % i) for i in range(len(b))] and create such a linear combination: sum([c[i]*b[i] for i in range(len(b))]); this is a vector over the Symbolic Ring SR.

If you want to display the linear combination in the way you wrote, you can do it like this: FormalSum([(c[i], b[i]) for i in range(len(b))], parent=FormalSums(SR)), or even the fancy display show(FormalSum([(c[i], b[i].column()) for i in range(len(b))], parent=FormalSums(SR))).