Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #15063

Re: Finding a function within an arbitrary expression

From "Dr. Wolfgang Hintze" <weh@snafu.de>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Finding a function within an arbitrary expression
Date 2013-07-01 09:41 +0000
Message-ID <kqrisq$4a3$1@smc.vnet.net> (permalink)
References <kqomkf$p7b$1@smc.vnet.net>
Organization Time-Warner Telecom

Show all headers | View raw


Am Sonntag, 30. Juni 2013 09:27:11 UTC+2 schrieb amannucci:
> I am trying to figure out what that pattern is for the following. The difficulty here is that I can think textually, but not in Mathematica patterns. 
> 
> 
> 
> I am looking for a function u[1,0] within a list of expressions. The function might not be defined yet. For example, a list of expressions might be:
> 
> 
> 
> {3*u[1,0], u[0,0]/10., 1/u[1,0], ...}
> 
> 
> 
> I want to find all the expressions that have the function u[1,0] in it. There is certainly a way to do this "textually". How would one do this with patterns? Is it possible? Thank you.

Hello,

You could use this function which looks even for a general pattern "pat" rather than just u[1,0]

f[pat_] = Complement[#1, Select[#1, FreeQ[#1, pat] & ]] &

Examples 

x = {3*u[1, 0], u[0, 0]/10., 1/u[1, 0], u[1, 0]/2., b*Sqrt[u[1, 0]]}


In[83]:= f[u[1, 0]][x]
Out[83]= {1/u[1, 0], b*Sqrt[u[1, 0]], 0.5*u[1, 0], 3*u[1, 0]}

In[82]:= f[u[0, 0]][x]
Out[82]= {0.1*u[0, 0]}

Best regards,
Wolfgang

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Finding a function within an arbitrary expression amannucci <Anthony.J.Mannucci@jpl.nasa.gov> - 2013-06-30 07:27 +0000
  Re: Finding a function within an arbitrary expression "Dr. Wolfgang Hintze" <weh@snafu.de> - 2013-07-01 09:41 +0000

csiph-web