Ask Your Question
3

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

asked 14 years ago

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?

Preview: (hide)

3 Answers

Sort by » oldest newest most voted
6

answered 14 years ago

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]
Preview: (hide)
link

Comments

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

kcrisman gravatar imagekcrisman ( 14 years ago )
1

One may also use the real ring RR

Joel Sjögren gravatar imageJoel Sjögren ( 12 years ago )

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 ( 11 years ago )
0

answered 6 years ago

Ernö gravatar image

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

Preview: (hide)
link
0

answered 13 years ago

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.

Preview: (hide)
link

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: 14 years ago

Seen: 9,306 times

Last updated: Jun 28 '18