Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #6773
| 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 | <jasv04$71l$1@smc.vnet.net> (permalink) |
| 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.
Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: Matrices as operators Ray Koopman <koopman@sfu.ca> - 2011-11-26 11:48 +0000 Re: Matrices as operators Chris Young <cy56@comcast.net> - 2011-11-27 09:13 +0000
csiph-web