MathGroup Archive 2005

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

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg54664] Re: [mg54626] Testing the 'type' of a root returned by Solve
  • From: Igor Antonio <igora at wolf-ram.com>
  • Date: Fri, 25 Feb 2005 01:19:25 -0500 (EST)
  • Organization: Wolfram Research, Inc.
  • References: <200502240821.DAA13301@smc.vnet.net>
  • Reply-to: igora at wolf-ram.com
  • Sender: owner-wri-mathgroup at wolfram.com

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"

Mike,

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

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

Out[66]=
{{r -> (-0.9982363561637702 - 1.7289960868380712*I)*
      Feet}, {r -> (-0.9982363561637694 +
       1.7289960868380714*I)*Feet},
   {r -> 1.9964727123275399*Feet}}

In[67]:=
Select[t, MatchQ[#[[1,2,1]], _Complex] & ]

Out[67]=
{{r -> (-0.9982363561637702 - 1.7289960868380712*I)*
      Feet}, {r -> (-0.9982363561637694 +
       1.7289960868380714*I)*Feet}}
-- 


Igor Antonio
Wolfram Research, Inc.
http://www.wolfram.com

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