Re: How to select terms wanted in a series
- To: mathgroup at smc.vnet.net
- Subject: [mg85929] Re: How to select terms wanted in a series
- From: Albert Retey <awnl at arcor.net>
- Date: Thu, 28 Feb 2008 02:44:54 -0500 (EST)
- References: <fq3bhj$gas$1@smc.vnet.net>
Hi, > I have an expression, which is a sum of large number of terms, e.g. > > expression = x + 2x*y - x*y*z + u*x*y + 3u^2 > > And I want to select out terms with the factor (x*y). e.g. > > The terms in "expression" that I want are 2x*y, -x*y*z, u*x*y > > My first step is, > > allterms = Apply[List, expression] > > Then, I don't know how to extract the terms I want, I use > > Select[allterms, (# == x*y*_)&] > > But It doesn't work. > > Anyone has some good ideas? any help will be appreciated much! > Sincerely Barrow > this would work in this case: Cases[allterms, HoldPattern[Times[___, x, ___, y, ___]]] Note that there are many pitfalls when working with patterns on mathematical expressions, so it is usually better to use functions that do the right thing. Here the following should be much more robust, I think: subterm=x*y; subterm*List@@Coefficient[expression,subterm] Depending on what you are trying to achieve I would recommend to look up Coefficient and CoefficientList in the Help. hth, albert