Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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)?

Thanks!

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

Try

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

EDIT then how about

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

N[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|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
add comment

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|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
add comment

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|improve this answer
add comment

Your Answer

 
discard

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.