MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Matrices as operators


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




  • Prev by Date: Re: Texture on Disk in Mathematica 8?
  • Next by Date: Re: Domain of a function
  • Previous by thread: Re: Matrices as operators
  • Next by thread: Re: Matrices as operators