Ask Your Question

solving simultaneous equations trouble using solve()

asked 2021-12-31 19:38:43 +0200

aurelius_nero gravatar image

Hi, I am having a lot of difficulty solving the following set of equations using solve. I am gonna insert my code below:

  sage: solve([f,g,h,j,k,l],w1,w2,w3,x1,x2,x3,solution_dict=True)

The output is:

 [{w1 + w2 + w3: 2},
 {w1*x1 + w2*x2 + w3*x3: 0},
 {w1*x1^2 + w2*x2^2 + w3*x3^2: 2/3},
 {w1*x1^3 + w2*x2^3 + w3*x3^3: 0},
 {w1*x1^4 + w2*x2^4 + w3*x3^4: 2/5},
 {w1*x1^5 + w2*x2^5 + w3*x3^5: 0}]

obviously this output doesn't help me as I need the solution for all six variables. Any help is appreciated please.

edit retag flag offensive close merge delete


For systems of polynomial equations, do not use the symbolic ring, but ideals in polynomial rings. See

FrédéricC gravatar imageFrédéricC ( 2021-12-31 19:45:31 +0200 )edit

@FrédéricC I am not sure how to do so. Could you elaborate a little more ?

aurelius_nero gravatar imageaurelius_nero ( 2021-12-31 20:09:06 +0200 )edit

2 Answers

Sort by » oldest newest most voted

answered 2021-12-31 20:19:44 +0200

FrédéricC gravatar image

Here is a minimal illustrating example:

sage: R = PolynomialRing(QQbar,'x,y')
sage: x, y = R.gens()
sage: I = R.ideal([x*x+y*y-1, x-5*y])
sage: I.variety()
[{y: -0.1961161351381841?, x: -0.9805806756909202?},
 {y: 0.1961161351381841?, x: 0.9805806756909202?}]
edit flag offensive delete link more


How do I even use any of this ? 1) what is the R.gens() 2) what is the R.ideal ? 3) what is I.variety ? 4) isn't there a simpler way to solve polynomials ?

aurelius_nero gravatar imageaurelius_nero ( 2021-12-31 22:17:03 +0200 )edit

The way suggested by FredericCis the simplest way to tackle general polynomial systems in Sage (and in general...).

See chapters 7 and 9 of this book for an introduction to the subject. Chapter 9 points to a textbook, which turns out to be easily Googleable,

BTW, I'd recommend reading the whole Sage book (and a good Python tutorial) to gain a deeper understanding of Sage...

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2022-01-01 12:11:47 +0200 )edit

answered 2021-12-31 23:23:30 +0200

aurelius_nero gravatar image

For all those interested I have manged to do what I wanted using sympy.

 sage: var('x1,x2,x3,w1,w2,w3')
 sage: f=w1+w2+w3==2;g=(w1*x1)+(w2*x2)+(w3*x3)==0;h=(w1*(x1)^2)+(w2*(x2)^2)+(w3*(x3)^2)==(2/3);j=(w1*(x1)^3)+(w2*(x2)^3)+(w3*(x3)^3)==0;k=(w1*(x1)^4)+(w2*(x2)^4)+(w3*(x3)^4)==(2/5);l=(w1*(x1)^5)+(w2*(x2)^5)+(w3*(x3)^5)==0
 sage: import sympy
 sage sympy.solve([f,g,h,j,k,l],w1,w2,w3,x1,x2,x3)


  [{w1: 5/9, w2: 5/9, w3: 8/9, x1: -sqrt(15)/5, x2: sqrt(15)/5, x3: 0},
  {w1: 5/9, w2: 5/9, w3: 8/9, x1: sqrt(15)/5, x2: -sqrt(15)/5, x3: 0},
  {w1: 5/9, w2: 8/9, w3: 5/9, x1: -sqrt(15)/5, x2: 0, x3: sqrt(15)/5},
  {w1: 5/9, w2: 8/9, w3: 5/9, x1: sqrt(15)/5, x2: 0, x3: -sqrt(15)/5},
  {w1: 8/9, w2: 5/9, w3: 5/9, x1: 0, x2: -sqrt(15)/5, x3: sqrt(15)/5},
  {w1: 8/9, w2: 5/9, w3: 5/9, x1: 0, x2: sqrt(15)/5, x3: -sqrt(15)/5}]

If anyone can enlighten me on how to use the polynomial rings to solve polynomial systems of equations I'd be very happy (I am also a noob at sagemath btw)

Thank you.

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

1 follower


Asked: 2021-12-31 19:38:43 +0200

Seen: 168 times

Last updated: Dec 31 '21