Ask Your Question
1

Cant find matrix kernel

asked 2018-03-09 21:33:07 +0100

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:

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]])
sol=solve(A.det(),x,solution_dict=True)
A.subs(x=sol[0][x]).right_kernel_matrix()

My output is simple:

[]
edit retag flag offensive close merge delete

Comments

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 10:59:35 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2018-03-10 10:53:05 +0100

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 http://scipy-cookbook.readthedocs.io/...)

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
-3.1648558730042146e-14
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

Comments

Nice! Thak you!

ianncunha gravatar imageianncunha ( 2018-03-10 19:06:19 +0100 )edit
1

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 10:52:56 +0100 )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

Stats

Asked: 2018-03-09 21:33:07 +0100

Seen: 424 times

Last updated: Mar 10 '18