ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 05 Feb 2013 09:54:17 +0100One-dimension subspacehttps://ask.sagemath.org/question/9767/one-dimension-subspace/I am looking for one-dimension subspace $x$ such that for every $v\in$$\langle x\rangle$ we have $v.v=0$.
I try this:
V = VectorSpace(GF(5),2)
for i in V.subspaces(1):
for x in i:
if (x*x==0):
print(i)
but I have trouble with it:
sage gives me subspace "Vector space of degree 2 and dimension 1 over Finite Field of size 5
Basis matrix:
[1 0]"
this subspace is not satisfied my condition Tue, 05 Feb 2013 03:33:19 +0100https://ask.sagemath.org/question/9767/one-dimension-subspace/Answer by ppurka for <p>I am looking for one-dimension subspace $x$ such that for every $v\in$$\langle x\rangle$ we have $v.v=0$. </p>
<p>I try this:</p>
<p>V = VectorSpace(GF(5),2)</p>
<pre><code>for i in V.subspaces(1):
for x in i:
if (x*x==0):
print(i)
</code></pre>
<p>but I have trouble with it:</p>
<p>sage gives me subspace "Vector space of degree 2 and dimension 1 over Finite Field of size 5
Basis matrix:
[1 0]"
this subspace is not satisfied my condition </p>
https://ask.sagemath.org/question/9767/one-dimension-subspace/?answer=14507#post-id-14507You need to take care of the zero element of the subspace. `for x in i` will iterate over all the vectors including the zero vector.Tue, 05 Feb 2013 05:27:55 +0100https://ask.sagemath.org/question/9767/one-dimension-subspace/?answer=14507#post-id-14507Comment by Babgen for <p>You need to take care of the zero element of the subspace. <code>for x in i</code> will iterate over all the vectors including the zero vector.</p>
https://ask.sagemath.org/question/9767/one-dimension-subspace/?comment=18307#post-id-18307how can I take care of the zero element?Tue, 05 Feb 2013 07:34:43 +0100https://ask.sagemath.org/question/9767/one-dimension-subspace/?comment=18307#post-id-18307Comment by ppurka for <p>You need to take care of the zero element of the subspace. <code>for x in i</code> will iterate over all the vectors including the zero vector.</p>
https://ask.sagemath.org/question/9767/one-dimension-subspace/?comment=18306#post-id-18306If the subspaces are not too big, you can do
for x in i[1:]:
# rest of your code
If the subspaces are big, then doing `i[1:]` will take time and memory. In this case, change your if condition
if x != i.zero_vector() and x*x == 0:
# rest of your code.
Tue, 05 Feb 2013 09:54:17 +0100https://ask.sagemath.org/question/9767/one-dimension-subspace/?comment=18306#post-id-18306