Re: patterns
- To: mathgroup at smc.vnet.net
- Subject: [mg3734] Re: patterns
- From: ianc (Ian Collier)
- Date: Sun, 14 Apr 1996 02:59:46 -0400
- Organization: Wolfram Research, Inc.
- Sender: owner-wri-mathgroup at wolfram.com
In article <4ki9uv$9dm at dragonfly.wolfram.com>, Susan Rempe <rempe at euclid.chem.washington.edu> wrote: > I have a list of numbers and symbols. > How can I collect all the members of the list > which have a common denominator? > > ex. list={Sin[theta]/r, Cos[theta]/(r*s), 2*Csc[theta]/(2*r)} > > Say I want to collect all members of the list with r in the denominator; > > i.e. answer=Sin[theta]/r; > If you know exactly what the denominator you want to select is then the folling will work: In[19]:= list={Sin[theta]/r, Cos[theta]/(r*s), 2*Csc[theta]/(2*r)} Out[19]= Sin[theta] Cos[theta] Csc[theta] {----------, ----------, ----------} r r s r In[20]:= ?Select Select[list, crit] picks out all elements ei of list for which crit[ei] is True. Select[list, crit, n] picks out the first n elements for which crit[ei] is True. In[21]:= Select[ list, Denominator[ # ]==r&] Out[21]= Sin[theta] Csc[theta] {----------, ----------} r r You can use more sophisticated selction criteria if you wish. I hope this helps. --Ian ----------------------------------------------------------- Ian Collier Wolfram Research, Inc. ----------------------------------------------------------- tel:(217) 398-0700 fax:(217) 398-0747 ianc at wolfram.com Wolfram Research Home Page: http://www.wolfram.com/ ----------------------------------------------------------- ==== [MESSAGE SEPARATOR] ====