Ask Your Question
0

Absence of column vectors

asked 2019-11-23 11:44:38 -0600

Kraig gravatar image

I'm curious as to why column vecotrs seem to be non-existent in sage. To give you some context, I work with the following system:

R3 = IntegerModRing(3)
c_7_4 = [
[1, 0, -2, 0, 0, 0, 1],    
[1, 1, 0, 0, -2, 0, 0],    
[0, 1, 1, 0, 0, -2, 0],    
[0, 0, 1, 1, 0, 0, -2],    
[0, -2, 0, 1, 1, 0, 0],    
[-2, 0, 0, 0, 1, 1, 0],    
[0, 0, 0, -2, 0, 1, 1]
]
C3 = Matrix(R3, c_7_4)     
B3 = C3.right_kernel().basis()

Clearly, the right kernel of C3 is a column vector, but if you run this code, you would find that

print(B3[0]) # returns a row vector
print(B3[0] * C3) # returns an answer
print(C3 * B3[0]) # returns an answer

Given that a column matrix should reasonably be written

[[a],[b]]

Why is this not the case? Specifically, is there a coding limitation to what the programmers can do which forces them to implement it in this way, or is there some mathematical usefulness to this which is beyond my understanding?

Thanks!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2019-11-23 13:06:34 -0600

vdelecroix gravatar image

updated 2019-11-23 13:07:53 -0600

There is no distinction between row vector and column vector in Sagemath

sage: v = vector((1,2,3))
sage: A = matrix(3, [1, -2, 3, 0, 1, -1, 2, 0, -2])
sage: A * v
(6, -1, -4)
sage: v * A
(7, 0, -5)

Sagemath vectors are different objects than 1 x n or n x 1 matrices. Matrices make a difference between rows and columns

sage: col_v = matrix(3, 1, [1, 2, 3])
sage: print(col_v)
[1]
[2]
[3]
sage: A * col_v
[ 6]
[-1]
[-4]

sage: row_v = matrix(1, 3, [1, 2, 3])
sage: print(row_v)
[1 2 3]
sage: row_v * A
[ 7  0 -5]

Of course both A * row_v and col_v * A will fail.

edit flag offensive delete link more

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: 2019-11-23 11:44:38 -0600

Seen: 23 times

Last updated: Nov 23