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.Sun, 02 Jul 2017 04:33:15 +0200quadratic formhttps://ask.sagemath.org/question/38132/quadratic-form/> Write a function in Sage that accepts as input a symmetrical bilinear (not trivial) form B [caracterized by the associated matrix respect to the canonical base in R^n] and gives in output a vector subspace W ⊆ R^n such that:
- Dim W is maximal
- the restriction B|wxw has maximum rankFri, 30 Jun 2017 01:17:32 +0200https://ask.sagemath.org/question/38132/quadratic-form/Comment by tmonteil for <blockquote>
<p>Write a function in Sage that accepts as input a symmetrical bilinear (not trivial) form B [caracterized by the associated matrix respect to the canonical base in R^n] and gives in output a vector subspace W ⊆ R^n such that:
- Dim W is maximal
- the restriction B|wxw has maximum rank</p>
</blockquote>
https://ask.sagemath.org/question/38132/quadratic-form/?comment=38137#post-id-38137This looks like homework.
If you want some help, you should ask more precise questions related to your research in solving those exercises, especially where you are locked.Fri, 30 Jun 2017 10:35:27 +0200https://ask.sagemath.org/question/38132/quadratic-form/?comment=38137#post-id-38137Comment by ciao for <blockquote>
<p>Write a function in Sage that accepts as input a symmetrical bilinear (not trivial) form B [caracterized by the associated matrix respect to the canonical base in R^n] and gives in output a vector subspace W ⊆ R^n such that:
- Dim W is maximal
- the restriction B|wxw has maximum rank</p>
</blockquote>
https://ask.sagemath.org/question/38132/quadratic-form/?comment=38141#post-id-38141i'm a sage beginner, i know what to do but i don't know how to implement it.. the idea is that i want to give in input a symmetrical nontrivial matrix A associated to the bilinear form B respect to the canonical base in R^n..then i want to obtain a subspace W⊆ R^n of maximal dimension such that the restriction B|wxw has max rank, in other words the matrix associated to this restriction has maximum rank and this condition occurs if kerW=[0].So i have to :
1. Give in input a matrix,
2. Declare the canonical basis of R^n and R
3. If B is the bilinear form and ei elements of the canonical base of R^n, i say that B(ei,ej)= A(i,j) with
A(i,j) the i,j element of A
4. Obtain a subspace W⊆ R^n(verifying that W.dimension is maximal) such that B|wxw isn't degenerate, in other words KerW=[0]Fri, 30 Jun 2017 13:22:34 +0200https://ask.sagemath.org/question/38132/quadratic-form/?comment=38141#post-id-38141Comment by dan_fulea for <blockquote>
<p>Write a function in Sage that accepts as input a symmetrical bilinear (not trivial) form B [caracterized by the associated matrix respect to the canonical base in R^n] and gives in output a vector subspace W ⊆ R^n such that:
- Dim W is maximal
- the restriction B|wxw has maximum rank</p>
</blockquote>
https://ask.sagemath.org/question/38132/quadratic-form/?comment=38146#post-id-38146Please give us a symmetric matrix `A` to work with. Relevant code to initialize it can be found after typing `?matrix` . Sample code for a matrix of my choice (maximal rank):
sage: A = matrix( QQ, 3, 3, [8,1,1, 1,8,1, 1,1,8 ] )
sage: A
[8 1 1]
[1 8 1]
[1 1 8]
sage: A.kernel()
Vector space of degree 3 and dimension 0 over Rational Field
Basis matrix:
[]Fri, 30 Jun 2017 17:30:04 +0200https://ask.sagemath.org/question/38132/quadratic-form/?comment=38146#post-id-38146Comment by ciao for <blockquote>
<p>Write a function in Sage that accepts as input a symmetrical bilinear (not trivial) form B [caracterized by the associated matrix respect to the canonical base in R^n] and gives in output a vector subspace W ⊆ R^n such that:
- Dim W is maximal
- the restriction B|wxw has maximum rank</p>
</blockquote>
https://ask.sagemath.org/question/38132/quadratic-form/?comment=38157#post-id-38157def function(Q):
#(Sylvester theorem to obtain a diagonalizing base)
n=Q.dim()
D=Q.rational_diagonal_form(return_matrix=True)[0]
M=Q.rational_diagonal_form(return_matrix=True)[1]
base=[M.column(i) for i in range(0,n)]
BASEpos=[]
BASEneg=[]
BASEnull=[]
for i in range(0,n):
if D[i,i]>0: BASEpos=BASEpos+[1/sqrt(D[i,i])*base[i]]
if D[i,i]<0: BASEneg=BASEneg+[1/sqrt(-D[i,i])*base[i]]
if D[i,i]==0: BASEnull=BASEnull+[base[i]]
Base1= BASEpos+BASEneg #(base without radical's vector to generate W)
Base2= BASEpos+BASEneg+BASEnull
W=span(SR,B1)
return W
When i give as input a quadratic form Q such as
Q=QuadraticForm(SR,4,[0,0,0,1,0,-1,0,0,0,0])
W=function(Q)
the program give me a lot of errorsSat, 01 Jul 2017 03:03:26 +0200https://ask.sagemath.org/question/38132/quadratic-form/?comment=38157#post-id-38157Answer by dan_fulea for <blockquote>
<p>Write a function in Sage that accepts as input a symmetrical bilinear (not trivial) form B [caracterized by the associated matrix respect to the canonical base in R^n] and gives in output a vector subspace W ⊆ R^n such that:
- Dim W is maximal
- the restriction B|wxw has maximum rank</p>
</blockquote>
https://ask.sagemath.org/question/38132/quadratic-form/?answer=38161#post-id-38161The following works (over `QQ` instead of `SR`):
def f( Q ):
D, M = Q.rational_diagonal_form( return_matrix=True )
base = M.columns()
BASEpos = []
BASEneg = []
BASEnull = []
for j in range( 0, Q.dim() ):
if D[j,j] > 0 : BASEpos += [ 1/sqrt( D[j,j] ) * base[j] ]
elif D[j,j] < 0 : BASEneg += [ 1/sqrt( -D[j,j] ) * base[j] ]
elif D[j,j] ==0 : BASEnull += [ base[j] ]
return span( QQ, BASEpos + BASEneg )
Q = QuadraticForm( QQ, 4, [ 0,0,0,1, 0,-1,0, 0,0, 0 ] )
f( Q )
Results:
Vector space of degree 4 and dimension 4 over Rational Field
Basis matrix:
[1 0 0 0]
[0 1 0 0]
[0 0 1 0]
[0 0 0 1]Sun, 02 Jul 2017 04:33:15 +0200https://ask.sagemath.org/question/38132/quadratic-form/?answer=38161#post-id-38161