Ask Your Question
0

need precise obvious values solving V^t A V =p(x0,x1), A, V matrix

asked 2023-01-16 08:56:26 +0200

ortollj gravatar image

updated 2023-01-16 10:52:11 +0200

Hi

Is there a way to avoid having to specify the values of a00 a11 to SageMath

( which values are obvious to a human ) so that SageMath finds the solution ?

print('https://www.youtube.com/watch?v=JabOq1XZi9c&t=823s')
print(' now suppose we get the polynomial with mixed product :')
R.<x1,x2> = PolynomialRing(QQ)
Vx=matrix([x1,x2])
p=2*(x1^2) - 4*x1*x2 + 5*(x2^2)
show('p(x1,x2) :',p)
print('first find the A matrix wich give this polynomial')
aVar=var('a00,a01,a10,a11')
A=matrix([ [a00,a01],[a10,a11] ])
VtAV=( Vx*A*(Vx.transpose()) ).det().expand()
show('VtAV : ',VtAV)

assume(a00,a11,'rational')
# to get symmetric matrix we need aij=aji

S=solve([VtAV==p,a01==a10],aVar)[0]
print(' no setting values for a00,a11 : ',S)

S=solve([VtAV==p,a00==2,a11==5,a01==a10],aVar)[0] 
print(' setting values  a00=2,a11=5 : ',S)
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2023-01-16 11:23:40 +0200

achrzesz gravatar image

updated 2023-02-15 18:10:32 +0200

One equality for polynomials denotes three equations for coefficients

R.<x1,x2> = PolynomialRing(SR)
Vx=matrix([x1,x2])
p=2*(x1^2) - 4*x1*x2 + 5*(x2^2)
var('a00,a01,a11')                   
A=matrix([ [a00,a01],[a01,a11] ])    # symmetry!
VtAV=Vx*A*(Vx.transpose()) 
p2=(VtAV-p)[0][0]           # scalar polynomial lhs-rhs
eq=[u==0 for u in p2.coefficients()] # equations
solve(eq,[a00,a01,a11])              # solving

[[a00 == 2, a01 == -2, a11 == 5]]

Shortcut:

R.<x1,x2> = PolynomialRing(QQ)
p=2*(x1^2) - 4*x1*x2 + 5*(x2^2)
q=QuadraticForm.from_polynomial(p);
q.Gram_matrix()

[ 2 -2]
[-2  5]
edit flag offensive delete link more

Comments

Thank you @achrzesz, yes make the matrix symmetric before solving !

ortollj gravatar imageortollj ( 2023-01-16 12:13:48 +0200 )edit

Congratulations @achrzesz, your shortcut is really the easiest way to do it !.Thank you I plus your answer.

R.<x1,x2,x3> = QQ[]

p= 4*x1^2 - 3*x1*x2 + 4*x2^2 - 3*x1*x3 - 3*x2*x3 - 2*x3^2

#Q = QuadraticForm(QQ, 3, [4,-3,-3,4,-3,-2])
#Q.Gram_matrix()

q=QuadraticForm.from_polynomial(p);
q.Gram_matrix()
ortollj gravatar imageortollj ( 2023-02-16 11:27:24 +0200 )edit
1

answered 2023-01-16 22:05:59 +0200

Emmanuel Charpentier gravatar image

Possible shortcut for @achrzesz's answer :

# Use SR
Vars = var(["a%d%d"%(i,j) for i in range(2) for j in range(2)] +\
           ["x%s"%i for i in (1,2)])
# V = matrix(Vars[4:])
# Can't parse the american obsession with "rows" and "columns" vectors :
# a vector is a vector is a vector...
U = vector(Vars[4:])
A = matrix(Vars[:4], ncols=2)
# Still in SR :
p = 2*x1^2-4*x1*x2+5*x2^2
# Useful polynomial rings
R1 = PolynomialRing(QQ, Vars[:4])
R2 = PolynomialRing(R1, Vars[4:])
# Solution as a polynomial ideal
J = R1.ideal((U*A*U-p).polynomial(ring=R2).coefficients() +\
             [a00-2, a11-5, a01-a10]) # Supplementary equations

then

sage: J
Ideal (a00 - 2, a01 + a10 + 4, a11 - 5, a00 - 2, a11 - 5, a01 - a10) of Multivariate Polynomial Ring in a00, a01, a10, a11 over Rational Field
sage: J.dimension()
0
sage: J.variety()
[{a11: 5, a10: -2, a01: -2, a00: 2}]

HTH,

edit flag offensive delete link more

Comments

Wow! Thank you @Emmanuel Charpentier, I realize that I only know how to use very few of the Mathematics possibilities of SageMath. But your answer depressed me a little !, I'm a little ashamed of my SageMath tinkering now .

But this [a00-2, a11-5, a01-a10]) # Supplementary equations is not elegant at all !

So that does not answer my question, since we artificially add equations so that SageMath can do the job .??

ortollj gravatar imageortollj ( 2023-01-17 06:51:36 +0200 )edit

But this [a00-2, a11-5, a01-a10]) # Supplementary equations is not elegant at all !

These are part of the specification of the problem you have to solve. Nothing specially elegant nor unelegant.

Possible alternative one-liner without "supplementary equations", and using SR's solve :

sage: solve(list(map(factor, (U*A*U-p).collect_common_factors().coefficients(x1, x2))),Vars[:4])
[[a00 == 2, a01 == r1, a10 == -r1 - 4, a11 == 5]]

since you haven't (yet) introduced the simmetry constraint, this answer (from Maxima's solver) is parametrized by a new (stillundeclared) variable r1 ; you have to introduce this constraint to be able to solve for r1 thus getting values for a01 and a10.

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2023-01-17 09:57:29 +0200 )edit

BTW, I added constraints for a00 and a11 by following your solution ; these turn out to be unnecessary :

sage: R1.ideal((U*A*U-p).polynomial(ring=R2).coefficients()+[a01-a10]).variety()
[{a11: 5, a10: -2, a01: -2, a00: 2}]

or, staying in SR :

sage: solve(list(map(factor, (U*A*U-p).collect_common_factors().coefficients(x1, x2))) + [a01==a10],Vars[:4])
[[a00 == 2, a01 == -2, a10 == -2, a11 == 5]]
Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2023-01-17 10:00:38 +0200 )edit

Ok, thank you @Emmanuel Charpentier

ortollj gravatar imageortollj ( 2023-01-17 10:35:22 +0200 )edit

I slightly modifying your code in order to make it more generic

https://sagecell.sagemath.org/?q=gkigiy

but Im not satisfy with my function getSymIdeal(A,xN) to get symmetric coefs value I m sure there is simpler way.

and something I do not understand is : #A.subs(Jvariety) # does not work, it produce error ! I dont know why . but it doesn't really matter.

ortollj gravatar imageortollj ( 2023-01-17 19:44:56 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2023-01-16 08:56:26 +0200

Seen: 172 times

Last updated: Feb 15 '23