Re: Simplify
- To: mathgroup at smc.vnet.net
- Subject: [mg91096] Re: Simplify
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Wed, 6 Aug 2008 05:04:25 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <g791is$9ng$1@smc.vnet.net>
Cetin Haftaoglu wrote: > I have a simple question about to simplify a expression (a list/matrices). I > have a list like > > {2 cet1, 0, -2 cet1, cet1, 0, -cet1} > > And I want to extract if possible the factor cet1, so I become a list like > > cet1{2, 0, -2, 1, 0, -1} Note that the above expression is *not* a list: This is the product of a symbol by a list. Evaluating such an expression will result in the original list (cet1 is distributed over the list). > How can I extract the factor? Among many other methods, you could use a transformation rule or a function such as *Coefficient[]* (Note that the last expression uses the non-commutative multiplication sign "**" to prevent distributivity): In[1]:= lst = {2 cet1, 0, -2 cet1, cet1, 0, -cet1} lst /. cet1 -> 1 Coefficient[lst, cet1] cet1 (lst /. cet1 -> 1) cet1 ** (lst /. cet1 -> 1) Out[1]= {2 cet1, 0, -2 cet1, cet1, 0, -cet1} Out[2]= {2, 0, -2, 1, 0, -1} Out[3]= {2, 0, -2, 1, 0, -1} Out[4]= {2 cet1, 0, -2 cet1, cet1, 0, -cet1} Out[5]= cet1 ** {2, 0, -2, 1, 0, -1} Regards, -- Jean-Marc