Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #6768 > unrolled thread
| Started by | Ray Koopman <koopman@sfu.ca> |
|---|---|
| First post | 2011-11-26 11:48 +0000 |
| Last post | 2011-11-27 09:13 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
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
| From | Ray Koopman <koopman@sfu.ca> |
|---|---|
| Date | 2011-11-26 11:48 +0000 |
| Subject | Re: Matrices as operators |
| Message-ID | <jaqjn9$oj7$1@smc.vnet.net> |
----- Christopher Young <cy56@comcast.net> wrote:
> On Nov 25, 2011, at 6:17 PM, Ray Koopman wrote:
>
>> This is simpler. Does it do what you want?
>> Note that 'mat' can be a ragged array.
>> Mapping at {-1} preserves its shape, whatever it may be.
>>
>> In[1]:= op[mat_,t_] := Map[#@t&, mat, {-1}]
>>
>> In[2]:= op[ { {Sin, Cos}, Tan, whatever }, t ]
>>
>> Out[2]= { {Sin[t], Cos[t]}, Tan[t], whatever[t] }
>
> Thanks very much, this is very close to what I need.
> I just need to keep the "[t]" from being added to numbers.
>
> In[1]:= op[mat_, t_] := Map[#1[t] &, mat, {-1}]
>
> In[2]:= op[{{Sin, Cos}, Tan, {Cos, 0, 1}}, t]
>
> Out[2]= {{Sin[t], Cos[t]}, Tan[t], {Cos[t], 0[t], 1[t]}}
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}}
[toc] | [next] | [standalone]
| From | Chris Young <cy56@comcast.net> |
|---|---|
| Date | 2011-11-27 09:13 +0000 |
| Message-ID | <jasv04$71l$1@smc.vnet.net> |
| In reply to | #6768 |
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.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web