Ask Your Question
3

How to get all (numerical) solutions of an equation?

asked 2010-08-25 11:42:23 +0100

kkumer gravatar image

Mathematica's NSolve can produce all roots of a polynomial equation, like this:

sage: mathematica('NSolve[9*x^6 + 4*x^4 + 3*x^3 + x - 17 == 0,  x]')
{{x -> -1.1030150726298147}, 
  {x -> -0.49110203599909275 - 0.9883314953720708*I}, 
  {x -> -0.49110203599909275 + 0.9883314953720708*I}, 
  {x -> 0.5426095723140001 - 1.0543115206871092*I}, 
  {x -> 0.5426095723140001 + 1.0543115206871092*I}, {x -> 1.}}

OTOH, Sage's solve gives just one real solution:

sage: solve(9*x^6 + 4*x^4 + 3*x^3 + x - 17 == 0,  x)
 [x == 1, 0 == 9*x^5 + 9*x^4 + 13*x^3 + 16*x^2 + 16*x + 17]

Is there a simple way to get all solutions?

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted
6

answered 2010-08-25 12:38:18 +0100

Mike Hansen gravatar image

You can use the roots method and specify that you want the results as complex numbers (say as elements of CC in Sage):

sage: eq = 9.0*x^6 + 4*x^4 + 3*x^3 + x - 17 == 0
sage: eq.roots(x, ring=CC, multiplicities=False)
[-1.10301507262981, 
 1.00000000000000, 
 -0.491102035999093 - 0.988331495372071*I, 
 -0.491102035999093 + 0.988331495372071*I,
 0.542609572314000 - 1.05431152068711*I, 
 0.542609572314000 + 1.05431152068711*I]
edit flag offensive delete link more

Comments

Yet another `ring` raising its ugly head ;) I wish I had time to make this easier to figure out.

kcrisman gravatar imagekcrisman ( 2010-08-25 13:45:45 +0100 )edit
1

One may also use the real ring RR

Joel Sjögren gravatar imageJoel Sjögren ( 2013-02-11 09:25:29 +0100 )edit

You may also select only the real portion of the answer: by doing something like : [ (real(cp)) for cp in (eq).roots(x, ring=CC, multiplicities=False)] . This will remove the imaginary portion of the answer.

Pavel Yartsev gravatar imagePavel Yartsev ( 2013-07-27 21:42:51 +0100 )edit
0

answered 2018-06-28 09:54:50 +0100

Ernö gravatar image

import numpy coeff=[9,0,4,3,0,1,-17] p=numpy.poly1d(coeff) r=numpy.roots(p) print str(r)

edit flag offensive delete link more
0

answered 2011-06-01 13:17:46 +0100

Juanlu001 gravatar image

It's strange, but I have tried this:

sage: eq = 9*x^6 + 4*x^4 + 3*x^3 + x - 17 == 0
sage: s = eq.solve(x, to_poly_solve = True)
sage: s
[0 == 9*x^5 + 9*x^4 + 13*x^3 + 16*x^2 + 16*x + 17, x == 1]
sage: s[0].solve(x, to_poly_solve = True)
[x == -1.10301507538, x == (-0.491102035999 - 0.988331495372*I), x == (0.542609572314 + 1.05431152069*I), x == (10757/10884*I - 3008/6125), x == (-2213/2099*I + 1127/2077)]

I expected the to_poly_solve option to work in the first case, but it didn't.

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

3 followers

Stats

Asked: 2010-08-25 11:42:23 +0100

Seen: 9,150 times

Last updated: Jun 28 '18