Ask Your Question
1

defining multivariate polynomial ring in script

asked 2020-02-07 14:16:21 +0100

mattb gravatar image

I'm trying to setup a multivariate polynomial ring within a generic python script so I can access the coefficients of an ellipse easily. One wrinkle in the problem is that I'm declaring variables that have an arbitrary display value. For instance,

theta1, theta2 = var('v1073, v1074')
f = 10.6*theta1**2 + 4.63*theta1*theta2 + 5.332*theta2**2 + 4.56*theta1 + 3.25456*theta2 - 43.54352

The reason I'm declaring a different value between the variable and the display value is because I'm using this same equation in a loop where I update the variable values to represent a current pair. This equation is being used to generate elliptical variable constraints in an optimization.

To the heart of the question. I can get the proper output for the coefficients if I declare a PolynomialRing lexographically. But this format is not compatible with a python script. How do you define the same PolynomialRing in another way? For example:

A.<theta1, theta2> = QQ[]; A
Multivariate Polynomial Ring in theta1, theta2 over Rational Field
f.coefficients()
[10.6, 4.63, 5.332, 4.56, 3.25456, -43.54352]

but

A = QQ['theta1', 'theta2']; A
Multivariate Polynomial Ring in theta1, theta2 over Rational Field
f.coefficients()
[[5.332*v1074^2 + 3.25456*v1074 - 43.54352, 0],
[4.63*v1074 + 4.56, 1],
[10.6, 2]]

I've tried a few other methods, but it doesn't seem to work. Even though when I look at the definition of A, I get the same answer as to what it represents. How can I define the ring, such that I get the correct answer?

edit retag flag offensive close merge delete

Comments

ook:

A = PolynomiaRing(QQ,['theta1', 'theta2'])
FrédéricC gravatar imageFrédéricC ( 2020-02-07 14:47:56 +0100 )edit

That gives me the same result as my second example.

mattb gravatar imagemattb ( 2020-02-08 00:59:48 +0100 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2020-02-08 12:09:24 +0100

tmonteil gravatar image

You could have a look at this answer:

https://ask.sagemath.org/question/333...

TL;DR replace:

A = QQ['theta1', 'theta2']

with:

A = QQ['theta1', 'theta2']
A.inject_variables()
edit flag offensive delete link more

Comments

Perfect! So simple, but didn't know about the 'inject_variables' method. Thanks!

mattb gravatar imagemattb ( 2020-02-22 18:39:48 +0100 )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: 2020-02-07 14:16:21 +0100

Seen: 446 times

Last updated: Feb 08 '20