MathGroup Archive 2005

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

Search the Archive

Testing the 'type' of a root returned by Solve

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.



(************** Content-type: application/mathematica **************
                     CreatedBy='Mathematica 5.0'

                    Mathematica-Compatible Notebook

This notebook can be used with any Mathematica-compatible
application, such as Mathematica, MathReader or Publicon. The data
for the notebook starts with the line containing stars above.

To get the notebook into a Mathematica-compatible application, do
one of the following:

* Save the data starting with the line of stars above into a file
  with a name ending in .nb, then open the file inside the

* Copy the data starting with the line of stars above to the
  clipboard, then use the Paste menu command inside the application.

Data for notebooks contains only printable 7-bit ASCII and can be
sent directly in email or through ftp in text mode.  Newlines can be
CR, LF or CRLF (Unix, Macintosh or MS-DOS style).

NOTE: If you modify the data for this notebook not in a Mathematica-
compatible application, you must delete the line below containing
the word CacheID, otherwise Mathematica-compatible applications may
try to use invalid cache data.

For more information on notebooks and Mathematica-compatible 
applications, contact Wolfram Research:
  email: info at
  phone: +1-217-398-0700 (U.S.)

Notebook reader applications are available free of charge from 
Wolfram Research.

(*CacheID: 232*)

(*NotebookOptionsPosition[      2544,         85]*)
(*NotebookOutlinePosition[      3174,        107]*)
(*  CellTagsIndexPosition[      3130,        103]*)

I want to be able to select the 'real' root using the 'Head' \
function, like this:\
\>", "Text",


    \(Head /@ \((r /. \ \((Solve[20 == \(4\ \[Pi]\ r\^3\)\/5, \ r] // 
              N)\))\)\)], "Input"],

    \({Complex, Complex, Real}\)], "Output"]
}, Open  ]],

But when I add a variable, then the 'type' of every root becomes \
'Times' because of the product of the variable and the number. Is 'Head' the \
wrong way to do this?\
\>", "Text",


    \(Head /@ \((r /. \((\ 
            Solve[20  Feet\^3 == \(4\ \[Pi]\ r\^3\)\/5, \ r] // 
              N)\))\)\)], "Input"],

    \({Times, Times, Times}\)], "Output"]
}, Open  ]]
FrontEndVersion->"5.0 for X",
ScreenRectangle->{{0, 1280}, {0, 1024}},
WindowSize->{520, 600},
WindowMargins->{{Automatic, 24}, {69, Automatic}}

Cached data follows.  If you edit this Notebook file directly, not
using Mathematica, you must remove the line containing CacheID at
the top of  the file.  The cache data will then be recreated when
you save this file from within Mathematica.



Cell[1754, 51, 123, 4, 52, "Text"],

Cell[1902, 59, 119, 2, 51, "Input"],
Cell[2024, 63, 58, 1, 27, "Output"]
}, Open  ]],
Cell[2097, 67, 207, 5, 71, "Text"],

Cell[2329, 76, 141, 3, 51, "Input"],
Cell[2473, 81, 55, 1, 27, "Output"]
}, Open  ]]

End of Mathematica Notebook file.

  • Prev by Date: Re: Show command trims bitmap edges? (newbie)
  • Next by Date: Re: Bar Chart Options Question
  • Previous by thread: Re: Monte Carlo Simulation Experiences
  • Next by thread: Re: Testing the 'type' of a root returned by Solve