Re: How do I pick out the expression under a radical?
- To: mathgroup at smc.vnet.net
- Subject: [mg36245] Re: How do I pick out the expression under a radical?
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Wed, 28 Aug 2002 04:16:05 -0400 (EDT)
- References: <akf64b$bgc$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
expr=a b x^2+5 x^3+5 Sqrt[4-x^2];
First note that Mathematica interprets Sqrt[u] as u^(1/2)
FullForm[Sqrt[u]]
Power[u,Rational[1,2]]
Now we can find the list of all u from subexpressions the form Sqrt[u_]:
Cases[expr, u_^(1/2) ->u,{0, Infinity}]
{4 - x^2}
Here {0, Infinity} causes the search to be over subexpressions at all
"levels" including level 0, which is the whole expression. The search will
not go inside "heads" unless we specify this:
Cases[expr[y], u_^(1/2) -> u, {0, Infinity}]
{}
Cases[expr[y], u_^(1/2) -> u, {0, Infinity},
Heads -> True]
{4 - x^2}
--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565
"Steve Beach" <asb4 at psu.edu> wrote in message
news:akf64b$bgc$1 at smc.vnet.net...
> I'm a poor physicist trying to figure out how to sort out the
> "physical" from the "non-physical" solutions to a problem. To do
> that, I need to be able to look at an expression and pick out a
> subexpression, the part under the radical.
>
> For example, say I've got the expression
>
> a b x^2 + 5 x^3 + 5 Sqrt[4 - x^2]
>
> I'd like to pick out "4 - x^2", which would then tell me that x is
> between +/- 2. I know there has got to be an easy way to do it, but I
> can't find it. Any help would be appreciated.
>
> Thanks,
>
> Steve Beach
> asb4 at psu.edu
> http://www.thebeachfamily.org
>