Re: Matrices as operators
- To: mathgroup at smc.vnet.net
- Subject: [mg123216] Re: Matrices as operators
- From: Chris Young <cy56 at comcast.net>
- Date: Sun, 27 Nov 2011 04:12:29 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <jaal4e$12d$1@smc.vnet.net> <jafu4b$ro7$1@smc.vnet.net> <janol1$aqb$1@smc.vnet.net> <jaqe26$nhv$1@smc.vnet.net>
Checking out the Help for Map, I found that you could put tests in with an If[ ] that was acting as a pure function. I think the following will always do what I want. Should be much faster than using While loops, too. op2[arr_, t_] := Map[ If[! (NumericQ[#] || StringQ[#]), #[t], # ] &, arr, {-1} ] In[38]:= op2[{{Sin, 3 E, Cos}, Tan, {Cos, Cos[Cos], 1}, "string"}, t] Out[38]= {{Sin[t], 3 E, Cos[t]}, Tan[t], {Cos[t], Cos[Cos[t]], 1}, "string"} The {-1} tells Map to only apply the change to the ends of the expression tree. The If[ ] filters out numbers and strings, which are not valid function names. Some more tests would have to be added if you wanted this to work for indexed functions such as f[k][x]. Seems like this is probably the fastest way to accomplish what I want, since it's all built-in. Amazing! Chris Young cy56 at comcast.net