Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have some functionals that have lots of parameters, but all are volume integrals (not really important...)

It's a variational function I'm minimizing and I'm only keeping the real solution (because it's my variational wavefunction and I demand only a real solution :) ).

Solve[D[Subscript[E, HO][\[CapitalPsi]] + Subscript[E, Int][\[CapitalPsi]], b] == 0, b]

Basically, a Solve for a parameter b. I get 5 roots, which is correct (fifth degree polynomial). Even when I add , Reals (no change, still five solutions, of which 4 complex) and try Reduce (some evil error message and none of the five answers). I even tried:

Simplify[Solve[D[Subscript[E, HO][\[CapitalPsi]] + Subscript[E, Int][\[CapitalPsi]], b] == 0, b], Element[b, Reals]]

Which apparently doesn't seem to work. The four complex solutions are of the form (-1)^(1/5) times a bunch of numbers/parameters. What can I do to filter out the rest (or only keep the first solution)?


share|cite|improve this question
up vote 2 down vote accepted


Assuming[Element[b,Reals],~rest of your code~]

EDIT then how about

b /. Solve[expr == 0, b]


Select[%,Element[#,Reals] & ]

I tried this using a regular polynomial with complex solutions and it worked in my case, should work in yours.

i.e, Create a list of solutions sols=Solve[expr==0,b]. Type sol// N to convert the fractional powers of 1 to "numerical" complex numbers Then use either Select or DeleteCases, which is a bit twisted and venture there only if Select didnt work. Or just numerically select sol[[n]] where n is the index of your real solution if you are willing to work the "shortcut" way.

share|cite|improve this answer
Same result, Mathematica seems unaware that $(-1)^{1/5}$ is a complex number... Although Im[(-1)^(1/5)] seems all right... – rubenvb Mar 15 '11 at 20:52

Method 1

roots = x /. Solve[x^5 == 1, x]
result1 = Select[roots, Im@# == 0 &]

Method 2

result2 = Solve[x^5 == 1, x, Reals]

Method 3

result3 = Reduce[x^5==1&&Element[x,Reals]]

Note that result1 is a list of numbers, result2 is list of lists of rules and result3 is an expression

share|cite|improve this answer
Be aware that method 2 does not work on Mathematica 7. – Mr.Wizard May 8 '11 at 11:56
@Mr.Wizard - I can believe it, Solve got a major upgrade in version 8 – Yaroslav Bulatov May 10 '11 at 4:35

Look at the FullForm to see what pattern you need to match.

In[1]:= FullForm[(-1)^(1/5)]

Out[1]//FullForm= Power[-1,Rational[1,5]]

Use DeleteCases to discard the unwanted solutions.

In[2]:= DeleteCases[{(-1)^(1/5)*p/q*4,(-1)^(1/5)*Pi,-p/q*5Pi},Power[-1,Rational[1,5]]*_]

Out[2]= {-(5 p Pi)/q)}

That will work as long as each of your solutions are a product of terms. If this doesn't work then post your actual solutions and I'll try to show how to craft a pattern to discard the unwanted solutions.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.