Ask Your Question

Cant find matrix kernel

asked 2018-03-09 14:33:07 -0500

ianncunha gravatar image

I have a symbolic matrix at the start and I use the determinant to find roots, ok. But when I input some solution of the determinant equation in the matrix again, sage is not able to find the kernel (null space). Here's my atempt:


My output is simple:

edit retag flag offensive close merge delete


I believe that the function solve is wrong by giving you exact symbolic expressions for the solutions

sage: A=matrix([[x^2,-1.75*x,0],[-1.75*x,x^2,2.07*i*x^2+4.65*i],[0,2.07*i*x^2+-4.65*i,x^2]])
sage: solve(A.det(),x)
[x == -sqrt(5/105698*sqrt(1865879629) + 30625/105698),
 x == sqrt(5/105698*sqrt(1865879629) + 30625/105698),
 x == -sqrt(-5/105698*sqrt(1865879629) + 30625/105698),
 x == sqrt(-5/105698*sqrt(1865879629) + 30625/105698), x == 0]

And this is part of the confusion here (it make no sense to substitute these "exact solutions" in your floating point matrix). I opened the trac ticket #24939 for this issue.

vdelecroix gravatar imagevdelecroix ( 2018-03-10 03:59:35 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2018-03-10 03:53:05 -0500

vdelecroix gravatar image

If you are mixing exact values with unexact ones it is unlikely that you get your answer. You have two solutions:

  • use floating point numbers everywhere. In this situation, you have to be careful by what you call a kernel since arithmetic operations are not exact (eg look below that the determinant is not exactly zero)
  • replace your floating point numbers 1.75, 2.07, etc by rational values 7/4, 207/100

To illustrate the first option using scipy (from the method at

sage: As = A.subs(x=sol[0][x]).change_ring(CDF)
sage: As
[  2.333101328217149   2.673036254461398                 0.0]
[  2.673036254461398   2.333101328217149 9.479519749409498*I]
[                0.0 0.179519749409498*I   2.333101328217149]
sage: As.det()      # small but not zero
sage: import scipy.linalg as linalg
sage: u, s, vh = linalg.svd(As.numpy())    # computing singular values decomposition
sage: s
array([  1.04215568e+01,   3.45036344e+00,   8.81146174e-16])

From above you see that the small singular value is the last one (that is correspond to the "approximate kernel"). Hence to get the corresponding vector into Sage you can just do

sage: k = vector(vh[2])
sage: k
(-0.7524244881834203, 0.6567372851130923, -0.050532444272992305*I)

And you can check that it is in the kernel

sage: As * k
(6.661338147750939e-16, 1.27675647831893e-15, -1.0547118733938987e-15*I)
edit flag offensive delete link more


Nice! Thak you!

ianncunha gravatar imageianncunha ( 2018-03-10 12:06:19 -0500 )edit

If this solves your question, you can mark this answer as accepted by clicking the "tick" sign at the top left of the answer. This way your question will appear as solved in the list of questions.

slelievre gravatar imageslelievre ( 2018-03-11 04:52:56 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2018-03-09 14:33:07 -0500

Seen: 21 times

Last updated: Mar 10