Ask Your Question
1

how to solve equations for polynomials coefficients?

asked 2020-03-22 12:34:11 +0200

amilton10 gravatar image

I am new to SAGE so sorry if this question is trivial. I have this code

  R2.<a0,a1,a2,a3, a4,b0,b1,b2,b3, b4,z,w,l,E,E1,v,t> = PolynomialRing(ZZ,17)
R.<x> = PowerSeriesRing(R2)
p = a1*x -a1*z*x**2+ a3*x**3+a4*x**4 +O(x**12)
k = b1*x+b2*x**2+ b3*x**3+b4*x**4 +O(x**12)
p1 = p.derivative()
p2 = p1.derivative()
y =2/x*(z-v*x)-E
x=2/x*a1*w*x**2
g=x*(p2 +y*p-x-E1*k)
v1=g.coefficients()
solve(v1[0],a3)

I am getting this error a3 is not a valid variable.

My question is how to solve equations for polynomials coefficients?

edit retag flag offensive close merge delete

Comments

1

solve is supposed to have (a listof) symbolic expressions (or symbolic expressions) as first argument, and (al list of) symbolic variables as second argument. in the call solve(v1[0], a3), both arguments are polynomials :

sage: v1[0].parent()
Multivariate Polynomial Ring in a0, a1, a2, a3, a4, b0, b1, b2, b3, b4, z, w, l, E, E1, v, t over Integer Ring
sage: a3.parent()
Multivariate Polynomial Ring in a0, a1, a2, a3, a4, b0, b1, b2, b3, b4, z, w, l, E, E1, v, t over Integer Ring

A possible workaround is :

sage: WA=SR(v1[0]).solve(SR(a3))[0]; WA
a3 == 1/3*a1*z^2 + 1/6*E*a1 + 1/6*E1*b1 + 1/3*a1*v + 1/3*a1*w

but note that

sage: WA.rhs().parent()
Symbolic Ring

I do not understand what

 x=2/x*a1*w*x**2

is supposed to mean...

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2020-03-22 20:01:50 +0200 )edit

By x = 2/x * a1 * w * x**2 do you mean that 2*a1*w should be considered equal to 1?

slelievre gravatar imageslelievre ( 2021-05-05 09:06:46 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-05-05 09:58:42 +0200

slelievre gravatar image

Maybe the following is what you want.

Having defined:

sage: R2.<a0, a1, a2, a3, a4, b0, b1, b2, b3, b4, z, w, l, E, E1, v, t> = QQ[]
sage: R.<x> = PowerSeriesRing(R2)

sage: p = a1 * x - a1 * z * x^2 + a3 * x^3 + a4 * x^4 + O(x^12)
sage: p1 = p.derivative()
sage: p2 = p1.derivative()

sage: k = b1 * x + b2 * x^2 + b3 * x^3 + b4 * x^4 + O(x^12)
sage: y = 2/x * (z - v * x) - E
sage: g = x * (p2 + y * p - x - E1 * k)

we get:

sage: g
(-2*a1*z^2 - a1*E - b1*E1 - 2*a1*v + 6*a3 - 1)*x^2
+ (a1*z*E + 2*a1*z*v + 2*a3*z - b2*E1 + 12*a4)*x^3
+ (2*a4*z - a3*E - b3*E1 - 2*a3*v)*x^4
+ (-a4*E - b4*E1 - 2*a4*v)*x^5
+ O(x^11)

Let's look at the coefficients of g, and specifically the constant one:

sage: cc = g.coefficients()
sage: cc
[-2*a1*z^2 - a1*E - b1*E1 - 2*a1*v + 6*a3 - 1,
 a1*z*E + 2*a1*z*v + 2*a3*z - b2*E1 + 12*a4,
 2*a4*z - a3*E - b3*E1 - 2*a3*v,
 -a4*E - b4*E1 - 2*a4*v]

sage: c = cc[0]
sage: c
-2*a1*z^2 - a1*E - b1*E1 - 2*a1*v + 6*a3 - 1

Dirty trick: to solve, move to the symbolic ring via strings:

sage: eq = SR(str(c))
sage: eq
-2*a1*z^2 - E*a1 - E1*b1 - 2*a1*v + 6*a3 - 1

sage: symbolic_a3 = SR('a3')

sage: sol = solve([eq], symbolic_a3, solution_dict=True)
sage: sol
[{a3: 1/3*a1*z^2 + 1/6*E*a1 + 1/6*E1*b1 + 1/3*a1*v + 1/6}]

Extract the value and take it back to the polynomial ring:

sage: s = sol[0]
sage: s
{a3: 1/3*a1*z^2 + 1/6*E*a1 + 1/6*E1*b1 + 1/3*a1*v + 1/6}

sage: my_symbolic_a3 = s[symbolic_a3]
sage: my_symbolic_a3
1/3*a1*z^2 + 1/6*E*a1 + 1/6*E1*b1 + 1/3*a1*v + 1/6

sage: my_a3 = R2(my_symbolic_a3)
sage: my_a3
1/3*a1*z^2 + 1/6*E*a1 + 1/6*E1*b1 + 1/3*a1*v + 1/6
edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2020-03-22 12:34:11 +0200

Seen: 502 times

Last updated: May 05 '21