3
$\begingroup$

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!

$\endgroup$
0

3 Answers 3

5
$\begingroup$

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

$\endgroup$
2
  • $\begingroup$ Be aware that method 2 does not work on Mathematica 7. $\endgroup$
    – Mr.Wizard
    May 8, 2011 at 11:56
  • $\begingroup$ @Mr.Wizard - I can believe it, Solve got a major upgrade in version 8 $\endgroup$ May 10, 2011 at 4:35
3
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ Same result, Mathematica seems unaware that $(-1)^{1/5}$ is a complex number... Although Im[(-1)^(1/5)] seems all right... $\endgroup$
    – rubenvb
    Mar 15, 2011 at 20:52
0
$\begingroup$

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.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .