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.Wed, 25 May 2016 18:26:46 +0200Find the kernel of a matrix $A$ and make it a matrix.https://ask.sagemath.org/question/33533/find-the-kernel-of-a-matrix-a-and-make-it-a-matrix/ I am trying to write a function that computes the monic genrator of an ideal $I\in k[x_1,\dots,x_n]$, i.e., the generator of $I\cap k[x_i]$ for each $i$. For this I need to use linear algebra for the set
$$\{1, x_i, x_i^2,\dots\}$$
I write each one of them in terms of the basis for the quotient ring $k[x_1,\dots,x_n]/I$, and see if they are linearly dependent.
Since I add in one more power a time, when I find a linearly dependent set, it should have nullity $1$. So if I can get the one element in basis of the kernel, I am done. But the $A.kernel()$ command in Sage gives me this:
N=M.kernel();N
Vector space of degree 2 and dimension 1 over Rational Field
Basis matrix:
[0 1]
Is there a way to assign it as a vector using the kernel command? Or do I have to write my own function to implement it? Thank you for your help!Tue, 24 May 2016 13:47:57 +0200https://ask.sagemath.org/question/33533/find-the-kernel-of-a-matrix-a-and-make-it-a-matrix/Answer by kcrisman for <p>I am trying to write a function that computes the monic genrator of an ideal $I\in k[x_1,\dots,x_n]$, i.e., the generator of $I\cap k[x_i]$ for each $i$. For this I need to use linear algebra for the set
$${1, x_i, x_i^2,\dots}$$
I write each one of them in terms of the basis for the quotient ring $k[x_1,\dots,x_n]/I$, and see if they are linearly dependent. </p>
<p>Since I add in one more power a time, when I find a linearly dependent set, it should have nullity $1$. So if I can get the one element in basis of the kernel, I am done. But the $A.kernel()$ command in Sage gives me this:</p>
<pre><code>N=M.kernel();N
Vector space of degree 2 and dimension 1 over Rational Field
Basis matrix:
[0 1]
</code></pre>
<p>Is there a way to assign it as a vector using the kernel command? Or do I have to write my own function to implement it? Thank you for your help!</p>
https://ask.sagemath.org/question/33533/find-the-kernel-of-a-matrix-a-and-make-it-a-matrix/?answer=33535#post-id-33535Borrowing an example from [Beezer's linear algebra text](http://linear.ups.edu/beta/section-FS.html) and [modifying it slightly](http://sagecell.sagemath.org/?z=eJxzVLBVyE0sKcqs0AgM1FGIjlYw1FHQNdZRMIzV4eVSQAPRukY6CiAV2GVBMgqmOGUtgSab6CgYxMZq8nL5AS121MtJTSuJz04tykvN0QAKlgEF_fSSEoszizU0ow1iebkKijLzShTKeLlKKgtSNco0AbjvJVA=&lang=sage):
A = matrix(QQ, [[ 1, -3, 1],
[-2, 1, 1],
[ 1, 5, 1],
[ 9, -4, 0]])
N = A.left_kernel()
v = N.basis()[0]
print v
type(v)
So you can access the basis, and if you're sure it's going to have just one element you can just get it as a vector. But in general a kernel is a vector space, so you can't just say "it" is a vector.Tue, 24 May 2016 15:14:51 +0200https://ask.sagemath.org/question/33533/find-the-kernel-of-a-matrix-a-and-make-it-a-matrix/?answer=33535#post-id-33535Comment by kcrisman for <p>Borrowing an example from <a href="http://linear.ups.edu/beta/section-FS.html">Beezer's linear algebra text</a> and <a href="http://sagecell.sagemath.org/?z=eJxzVLBVyE0sKcqs0AgM1FGIjlYw1FHQNdZRMIzV4eVSQAPRukY6CiAV2GVBMgqmOGUtgSab6CgYxMZq8nL5AS121MtJTSuJz04tykvN0QAKlgEF_fSSEoszizU0ow1iebkKijLzShTKeLlKKgtSNco0AbjvJVA=&lang=sage">modifying it slightly</a>:</p>
<pre><code>A = matrix(QQ, [[ 1, -3, 1],
[-2, 1, 1],
[ 1, 5, 1],
[ 9, -4, 0]])
N = A.left_kernel()
v = N.basis()[0]
print v
type(v)
</code></pre>
<p>So you can access the basis, and if you're sure it's going to have just one element you can just get it as a vector. But in general a kernel is a vector space, so you can't just say "it" is a vector.</p>
https://ask.sagemath.org/question/33533/find-the-kernel-of-a-matrix-a-and-make-it-a-matrix/?comment=33545#post-id-33545I'm not sure what you mean. Just don't import scipy at the beginning of your session. Unfortunately I don't think there is a way to undo a python import statement in a session.Wed, 25 May 2016 18:26:09 +0200https://ask.sagemath.org/question/33533/find-the-kernel-of-a-matrix-a-and-make-it-a-matrix/?comment=33545#post-id-33545Comment by KittyL for <p>Borrowing an example from <a href="http://linear.ups.edu/beta/section-FS.html">Beezer's linear algebra text</a> and <a href="http://sagecell.sagemath.org/?z=eJxzVLBVyE0sKcqs0AgM1FGIjlYw1FHQNdZRMIzV4eVSQAPRukY6CiAV2GVBMgqmOGUtgSab6CgYxMZq8nL5AS121MtJTSuJz04tykvN0QAKlgEF_fSSEoszizU0ow1iebkKijLzShTKeLlKKgtSNco0AbjvJVA=&lang=sage">modifying it slightly</a>:</p>
<pre><code>A = matrix(QQ, [[ 1, -3, 1],
[-2, 1, 1],
[ 1, 5, 1],
[ 9, -4, 0]])
N = A.left_kernel()
v = N.basis()[0]
print v
type(v)
</code></pre>
<p>So you can access the basis, and if you're sure it's going to have just one element you can just get it as a vector. But in general a kernel is a vector space, so you can't just say "it" is a vector.</p>
https://ask.sagemath.org/question/33533/find-the-kernel-of-a-matrix-a-and-make-it-a-matrix/?comment=33537#post-id-33537Thank you. This works perfectly. And I am pretty sure I'll have one element in the basis. But I'll change the title. One more question, I also defined matrix A using "A=matrix(...)" and it worked. But after I tried import scipy, it does not work anymore. I have to do "A=Matrix(...)" instead. Since I don't want to use scipy anymore, is there a way to "export" this package?Tue, 24 May 2016 15:26:51 +0200https://ask.sagemath.org/question/33533/find-the-kernel-of-a-matrix-a-and-make-it-a-matrix/?comment=33537#post-id-33537Comment by kcrisman for <p>Borrowing an example from <a href="http://linear.ups.edu/beta/section-FS.html">Beezer's linear algebra text</a> and <a href="http://sagecell.sagemath.org/?z=eJxzVLBVyE0sKcqs0AgM1FGIjlYw1FHQNdZRMIzV4eVSQAPRukY6CiAV2GVBMgqmOGUtgSab6CgYxMZq8nL5AS121MtJTSuJz04tykvN0QAKlgEF_fSSEoszizU0ow1iebkKijLzShTKeLlKKgtSNco0AbjvJVA=&lang=sage">modifying it slightly</a>:</p>
<pre><code>A = matrix(QQ, [[ 1, -3, 1],
[-2, 1, 1],
[ 1, 5, 1],
[ 9, -4, 0]])
N = A.left_kernel()
v = N.basis()[0]
print v
type(v)
</code></pre>
<p>So you can access the basis, and if you're sure it's going to have just one element you can just get it as a vector. But in general a kernel is a vector space, so you can't just say "it" is a vector.</p>
https://ask.sagemath.org/question/33533/find-the-kernel-of-a-matrix-a-and-make-it-a-matrix/?comment=33546#post-id-33546BTW, if this solved your question then be sure to click the check mark so that others coming to it know it was the right answer. Glad to help!Wed, 25 May 2016 18:26:46 +0200https://ask.sagemath.org/question/33533/find-the-kernel-of-a-matrix-a-and-make-it-a-matrix/?comment=33546#post-id-33546