Ask Your Question
0

Absence of column vectors

asked 5 years ago

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!

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
3

answered 5 years ago

vdelecroix gravatar image

updated 5 years ago

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.

Preview: (hide)
link

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: 5 years ago

Seen: 580 times

Last updated: Nov 23 '19