Re: Re: Extracting terms from an equation
- To: mathgroup at smc.vnet.net
- Subject: [mg69811] Re: [mg69786] Re: Extracting terms from an equation
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Sat, 23 Sep 2006 23:45:02 -0400 (EDT)
- Reply-to: hanlonr at cox.net
It has to do with the different levels at which x appears. FreeQ looks at multiple levels whereas MemberQ is targeted at one or more levels. expr=a+b*x^2+c*y^2+d*x*y+e*x^3; Cases[expr, _?(!FreeQ[#1, x]&)] {b*x^2, e*x^3, d*x*y} Cases[expr, _?(MemberQ[#1, x, 2]&)] {b*x^2, e*x^3, d*x*y} Cases[expr, _?(MemberQ[#1, x, {2}]&)] {b*x^2, e*x^3} Bob Hanlon ---- dimmechan at yahoo.com wrote: > Can someone explain the difference in the following? > > Cases[a + b*x^2 + c*y^2 + d*x*y + e*x^3, _?( !FreeQ[#1, x] & )] > {b*x^2, e*x^3, d*x*y} > > Cases[a + b*x^2 + c*y^2 + d*x*y + e*x^3, _?(MemberQ[#1, x] & )] > {d*x*y} > > Thanks > > Ã?Ÿ/Ã?â?? Coleman, Mark Ã?ÂÃ?³Ã?Â?Ã?±Ã?Ë?Ã?µ: > > Greetings, > > > > I'd like to find a general way to extract all of the terms from an > > equation that involve a given variable. For instance, consider the > > equation > > > > myEquation == Exp[a + b x^2 + c y^2 + d x y + e x^3]] > > > > I'd like to define a function such that > > > > myFunction[myEquation,x] returns the result {b x^2, d x y, e x^3} > > > > Thanks, > > > > -Mark >