Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #6770
| From | Chris Young <cy56@comcast.net> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Matrices as operators |
| Date | 2011-11-27 09:13 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jasuv5$6ui$1@smc.vnet.net> (permalink) |
| 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@comcast.net
Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread
Matrices as operators Chris Young <cy56@comcast.net> - 2011-11-20 10:34 +0000
Re: Matrices as operators Simon <simonjtyler@gmail.com> - 2011-11-21 09:29 +0000
Re: Matrices as operators Ray Koopman <koopman@sfu.ca> - 2011-11-22 10:39 +0000
Re: Matrices as operators Chris Young <cy56@comcast.net> - 2011-11-25 09:54 +0000
Re: Matrices as operators Ray Koopman <koopman@sfu.ca> - 2011-11-26 10:12 +0000
Re: Matrices as operators Chris Young <cy56@comcast.net> - 2011-11-27 09:13 +0000
csiph-web