Ask Your Question
0

Calculation Kernel of a matrix

asked 2017-11-15 08:38:29 -0600

studentboy gravatar image

updated 2017-11-15 11:32:45 -0600

I'm trying to write a program in which one part is related to calculation of kernel of a matrix. Its output and expected output are different. For example,

A = [[1, 0, 1], [1, 0, 0], [0, 1, 1], [0, 1, 0], [0, 0, 1], [-1, 0, 0], [0, 0, -1], [0, -1, 1], [0, -1, 0], [-1, 0, 1]]

A is the matrix whose kernel is wanted.

When I calculate its kernel with some programs they give output different, my program is as well. But, when I try to calculate its kernel some others, like SAGE, give output,

1  0  0  0  0  0  0 -2  2  1
0  1  0  0  0  0  0 -1  1  1
0  0  1  0  0  0  0 -1  2  0
0  0  0  1  0  0  0  0  1  0
0  0  0  0  1  0  0 -1  1  0
0  0  0  0  0  1  0  1 -1 -1
0  0  0  0  0  0  1  1 -1  0

The above one is what I expect as output. What is the point that I may overlook?

Here is my procedure to calculate the kernel in my program,

A.transposeInPlace();
FullPivLU<MatrixXf> lu(A);
MatrixXf A_null_space = lu.kernel();
A_null_space.transposeInPlace();

But in that way, I get different then expected one, but SAGE gives the above matrix that actually I expect.

 0.5    0   -1    1    0    0    0    0    0  0.5
-0.5    0   -0    0    1    0    0    0    0 -0.5
 0.5    0   -0    0    0    1    0    0    0 -0.5
 0.5    0   -0    0    0    0    1    0    0  0.5
  -1    0    1    0    0    0    0    1    0   -1
-0.5    0    1    0    0    0    0    0    1 -0.5
-0.5    1   -0    0    0    0    0    0    0  0.5

I'm really but really confused because both matrix seem right! How come?

Sage's output proof, https://i.stack.imgur.com/F3ryq.png My program's output proof, https://i.stack.imgur.com/7Mw8y.png

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-11-15 08:55:27 -0600

tmonteil gravatar image

Your matrix acts on column vectors to the right and on row vectors to the left (there is some duality here but it is not important in first approach). So, it can be considered either as a linear map \mathbb{Q}^3\to \mathbb{Q}^10 or as a linear map \mathbb{10}^3\to \mathbb{Q}^3 , respectively.

It has rank 3, so in the first case, the kernel is trivial, in the second case the kernel has dimension 7.

Here is some code to understand what i just wrote:

sage: A = matrix(QQ, [[1, 0, 1], [1, 0, 0], [0, 1, 1], [0, 1, 0], [0, 0, 1], [-1, 0, 0], [0, 0, -1], [0, -1, 1], [0, -1, 0], [-1, 0, 1]])
sage: A
[ 1  0  1]
[ 1  0  0]
[ 0  1  1]
[ 0  1  0]
[ 0  0  1]
[-1  0  0]
[ 0  0 -1]
[ 0 -1  1]
[ 0 -1  0]
[-1  0  1]

sage: A.parent()
Full MatrixSpace of 10 by 3 dense matrices over Rational Field

sage: A.rank()
3

sage: A.right_kernel()
Vector space of degree 3 and dimension 0 over Rational Field
Basis matrix:
[]

sage: A.right_kernel().dimension()
0

sage: K = A.left_kernel()
sage: K
Vector space of degree 10 and dimension 7 over Rational Field
Basis matrix:
[ 1  0  0  0  0  0  0 -2  2  1]
[ 0  1  0  0  0  0  0 -1  1  1]
[ 0  0  1  0  0  0  0 -1  2  0]
[ 0  0  0  1  0  0  0  0  1  0]
[ 0  0  0  0  1  0  0 -1  1  0]
[ 0  0  0  0  0  1  0  1 -1 -1]
[ 0  0  0  0  0  0  1  1 -1  0]

sage: K.dimension()
7

sage: K.basis()
[
(1, 0, 0, 0, 0, 0, 0, -2, 2, 1),
(0, 1, 0, 0, 0, 0, 0, -1, 1, 1),
(0, 0, 1, 0, 0, 0, 0, -1, 2, 0),
(0, 0, 0, 1, 0, 0, 0, 0, 1, 0),
(0, 0, 0, 0, 1, 0, 0, -1, 1, 0),
(0, 0, 0, 0, 0, 1, 0, 1, -1, -1),
(0, 0, 0, 0, 0, 0, 1, 1, -1, 0)
]

sage: K.basis()[0]
(1, 0, 0, 0, 0, 0, 0, -2, 2, 1)

sage: K.basis()[0] * A
(0, 0, 0)
edit flag offensive delete link more

Comments

Wow, that's a great help for me, really thank you. However, do you have an idea(algorithm) that helps to calculate the left kernel form? as shown on my code,

A.transposeInPlace();
FullPivLU<MatrixXf> lu(A);
MatrixXf A_null_space = lu.kernel();
A_null_space.transposeInPlace();

If write like this, it gives,

Null space:
 0.5    0   -1    1    0    0    0    0    0  0.5
-0.5    0   -0    0    1    0    0    0    0 -0.5
 0.5    0   -0    0    0    1    0    0    0 -0.5
 0.5    0   -0    0    0    0    1    0    0  0.5
  -1    0    1    0    0    0    0    1    0   -1
-0.5    0    1    0    0    0    0    0    1 -0.5
-0.5    1   -0    0    0    0    0    0    0  0.5
studentboy gravatar imagestudentboy ( 2017-11-15 10:44:57 -0600 )edit

But expected,

1  0  0  0  0  0  0 -2  2  1
0  1  0  0  0  0  0 -1  1  1
0  0  1  0  0  0  0 -1  2  0
0  0  0  1  0  0  0  0  1  0
0  0  0  0  1  0  0 -1  1  0
0  0  0  0  0  1  0  1 -1 -1
0  0  0  0  0  0  1  1 -1  0
studentboy gravatar imagestudentboy ( 2017-11-15 10:46:19 -0600 )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

1 follower

Stats

Asked: 2017-11-15 08:38:29 -0600

Seen: 26 times

Last updated: Nov 15