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


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

Re: Matrices as operators

From Chris Young <cy56@comcast.net>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Matrices as operators
Date 2011-11-25 09:54 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <janol1$aqb$1@smc.vnet.net> (permalink)
References <jaal4e$12d$1@smc.vnet.net> <jafu4b$ro7$1@smc.vnet.net>

Show all headers | View raw


On 2011-11-22 10:39:07 +0000, Ray Koopman said:

> If you're worried about redundant calculations when the matrices
> are bigger than 2 x 2 and the functions are more complicated than
> Sin and Cos, try something like
> 
> R[t_] := {{#1,-#2},{#2,#1}}&[Cos@t,Sin@t]


> You could have the expression optimizer even further optimize that
> 
> Experimental`OptimizeExpression[{{#1, -#2}, {#2, #1}} &[Cos@t, Sin@t]]
> 
> (That is what happens in Compile)
> 
> Oliver

These look useful for speeding up calculations, and also clarifying the 
structure of matrices.

For what I was looking for though (applying a matrix of different 
function names, such as "Sin" and "Cos", to the same parameter, such as 
the angle theta) I think the following will work.

I got unflatten[ ] from the Help for Partition (in the Applications section).
I was hoping that Partition alone would work, but reconstructing the 
original array is more complicated than I thought. Not sure exactly 
what Fold[ ] is doing here. Would like to try running this through the 
debugger.

At any rate, I think the op[ ] routine I made will apply any array 
("tensors", not just rectangular matrices) to a parameter as an 
operator.

Partition a flat list of elements into a multidimensional array with 
specified dimensions.
(Take[{2, 3, 4, 5}, {-1, 2, -1} means take the elements from the last 
through the second.)

unflatten[
   list_,
   {dims__?((IntegerQ[#] && Positive[#]) &)}] \
   := 
 Fold[
    Partition, list, Take[{dims}, {-1, 2, -1}]
    ]  \
    /;
  (Length[list] === Times[dims])

This will apply matrix mat as an operator to the parameter θ :

op[mat_, θ_] := unflatten[
  Through[Flatten[mat][θ]], Dimensions[mat]
  ]


In[536]:=

op[( {
   {Cos, -Sin},
   {Sin, Cos}
  } ), θ]


Out[536]=

{{Cos[θ], (-Sin)[θ]},  {Sin[θ], Cos[θ]}}



Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Next 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