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.Fri, 07 Feb 2020 14:16:21 +0100defining multivariate polynomial ring in scripthttps://ask.sagemath.org/question/49842/defining-multivariate-polynomial-ring-in-script/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?mattbFri, 07 Feb 2020 14:16:21 +0100https://ask.sagemath.org/question/49842/How can I map functions into polynomial coefficientshttps://ask.sagemath.org/question/48492/how-can-i-map-functions-into-polynomial-coefficients/Let's say I have the following expression (from a wide range of possibilities) :
pol = 3*a*x^(-b)*log(x)*b^2 - 6*a*b*c*sin(x*b) + 3*a*c^2 + 5
And I want to extract the coefficients of the polynomial over the polynomial ring over a & c, so that these result in:
a^0*c^0 : 5
a^1*c^0 : 3*x^(-b)*log(x)*b^2
a^0*c^1 : 0
a^1*c^1 : -6*b*sin(x*b)
etc.
How can I define the polynomial ring?
How can I map an existing expression that defines "pol" (which is the result of other manipulations) into such ring?Edgar BrownFri, 25 Oct 2019 03:07:32 +0200https://ask.sagemath.org/question/48492/