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


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

Re: Matrices as operators

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!209.197.12.242.MISMATCH!nx01.iad01.newshosting.com!newshosting.com!news-out.readnews.com!news-xxxfer.readnews.com!newspump.sol.net!post2.nntp.sol.net!posts.news.twtelecom.net!nnrp2.twtelecom.net!not-for-mail
From Chris Young <cy56@comcast.net>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Matrices as operators
Date Sun, 27 Nov 2011 09:13:09 +0000 (UTC)
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Sender steve@smc.vnet.net
Approved Steven M. Christensen <steve@smc.vnet.net>, Moderator
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>
Lines 34
NNTP-Posting-Date 27 Nov 2011 08:17:31 GMT
NNTP-Posting-Host c18e9bbf.news.twtelecom.net
X-Trace DXC=`[>\HaNI06fnBa5FI7EIm`C_A=>8kQj6mm^eQlV`f18gSkSnfSS@:ceEFiONJ7[GofFk?9RnGBf0h
X-Complaints-To abuse@twtelecom.net
Xref x330-a1.tempe.blueboxinc.net comp.soft-sys.math.mathematica:6770

Show key headers only | View raw


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


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