Re: Matrices as operators
- To: mathgroup at smc.vnet.net
- Subject: [mg123214] Re: Matrices as operators
- From: Ray Koopman <koopman at sfu.ca>
- Date: Sat, 26 Nov 2011 06:48:12 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
----- Christopher Young <cy56 at 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}}