MathGroup Archive 2006

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

Search the Archive

Re: Extracting terms from an equation


Hi,

> 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}

MemberQ by default checks for precense of x in the first level only. What
you probably want is:

Cases[a + b*x^2 + c*y^2 + d*x*y + e*x^3, _?(MemberQ[#1, x,Infinity] & )]

which should always give the same result as the version with FreeQ. Use

In[4]:= FullForm[e*x^3]
Out[4]//FullForm=
Times[e, Power[x, 3]]

to understand why x is not a member of e*x^3 , but x^3 is...


hth,

albert


  • Prev by Date: Re: DSolve fails with Telegraph equation
  • Next by Date: Re: Add Quotation Marks to Data in a file
  • Previous by thread: Re: Re: Extracting terms from an equation
  • Next by thread: Re: Re: Extracting terms from an equation