MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Testing the 'type' of a root returned by Solve

Mike Witt wrote:
> If I solve an equation in which the solutions turn out
> to be functions of some variable, I can't figure out how
> to pick out one of the roots based on whether the root is
> real or complex.
> The problem is that Head[] reports that the roots are
> all "Times" because of the variable in them.
> The following notebook demonstrates. Can someone tell me
> the right way to do this (or point me to the right place
> in the book or help pages?)
> For private email remove the NOSPAM.
> -Mike
>  filename="foo.nb"


What you should try to use is the Select[] and Cases function, as that's 
what they were designed for. :-)

This solution only works for this cases since it depends on the position 
of the complex number in the expression.  There might be a more elegant 
way to do this, but if your numbers are always in that same structured

var = N[Solve[20*Feet^3 == (4*Pi*r^3)/5, r]]

{{r -> (-0.9982363561637702 - 1.7289960868380712*I)*
      Feet}, {r -> (-0.9982363561637694 +
   {r -> 1.9964727123275399*Feet}}

Select[t, MatchQ[#[[1,2,1]], _Complex] & ]

{{r -> (-0.9982363561637702 - 1.7289960868380712*I)*
      Feet}, {r -> (-0.9982363561637694 +

Igor Antonio
Wolfram Research, Inc.

To email me personally, remove the dash.

  • Prev by Date: Re: Simplify and Abs
  • Next by Date: Re: comparing two lists
  • Previous by thread: Testing the 'type' of a root returned by Solve
  • Next by thread: OO System for Mathematica