Re: patterns

*To*: mathgroup at smc.vnet.net*Subject*: [mg3744] Re: patterns*From*: gaylord at ux1.cso.uiuc.edu (richard j. gaylord)*Date*: Sun, 14 Apr 1996 03:01:30 -0400*Organization*: university of illinois*Sender*: owner-wri-mathgroup at wolfram.com

In article <4kkth9$7jl at dragonfly.wolfram.com>, ianc at wolfram.com (Ian Collier) wrote: > 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 > ian [and the others who have posted responses to this question]: you've all apparently missed the point of what this person wants to do [i think]. she wants ONLY Sin[theta]/r to be returned, not 2*Csc[theta]/(2*r) as well. i'd give the answer to this question, myself but there is too little room in the margin to fit it in. -fermat- -- "if you're not programming functionally, then you're programming dysfunctionally" ==== [MESSAGE SEPARATOR] ====