Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

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

Search the Archive

Re: Matrices as operators

  • To: mathgroup at smc.vnet.net
  • Subject: [mg123217] Re: Matrices as operators
  • From: Chris Young <cy56 at comcast.net>
  • Date: Sun, 27 Nov 2011 04:12:40 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <jaal4e$12d$1@smc.vnet.net> <jaqjn9$oj7$1@smc.vnet.net>

On 2011-11-26 11:48:57 +0000, Ray Koopman said:

> This won't try to interpret a number as a function:
> 
> In[1]:= op[mat_, t_] := Map[If[NumericQ@#, #, #@t] &, mat, {-1}]
> 
> In[2]:= op[{{Sin, Cos}, Tan, {Cos, 0, 1}}, t]
> 
> Out[2]= {{Sin[t], Cos[t]}, Tan[t], {Cos[t], 0, 1}}

Just discovered a notation I like a lot for pure functions: the 
standard "tee-arrow" notation can be used wherever a pure function can 
be used! This is explained on the Help page for "Function", in the 
"More Information" section.

Function[x, body]

or

# body &

can always be converted to the "tee-arrow" form, I believe.

The tee-arrow is entered by typing Escape fn Escape.

So the matrix-operator function Ix had earlier,

op[arr_, t_] :=
 Map[
  If[! (NumericQ[#] || StringQ[#]),
    #[t],
    #
    ] &,
  arr,
  {-1}
  ]

would become (in input form)

op[arr_, t_] :=
 Map[
  x \[Function] If[! (NumericQ[x] \[Or] StringQ[x]), x[t], x],
  arr,
  {-1}
  ]

Applying this to the test array
arr = {{Sin, Cos}, Tan, {Cos, Cos[Cos], 1}, "string"},
we get

In[100]:= op2[arr, t]

Out[100]= {{Sin[t], Cos[t]}, Tan[t], {Cos[t], Cos[Cos[t]], 1}, "string"}


I can't type out the tee-arrow in text form, but it goes where 
"\[Function]" appears above.




  • Prev by Date: Re: Multiple operations in a "Do" expression
  • Next by Date: Re: Root finding needs higher accuracy
  • Previous by thread: Re: Matrices as operators
  • Next by thread: How-to create a mathematica notebook in a Java program ?