TransWikia.com

How should I define the Cayley transform?

Mathematica Asked by the_lar on May 24, 2021

I am a beginner to Mathematica. I am trying to define a function which would evalute the Cayley matrix transform, namely taking a matrix $M$ such that $I + M$ is invertible to $(I-M)(I+M)^{-1}$. I guess I would first like to cover 2-by-2 matrices.

My code is

cayley[x_] := 
  (IdentityMatrix[2] - x) . (Inverse[IdentityMatrix[2] + x]) ; 
  Det[IdentityMatrix[2] + x] != 0

I am getting an error.

cayley[x_] cannot be followed by …

Surely there is some very basic syntax error, but after some trial and error I cannot figure it out from the documentation or the content of the error message. Any help much appreciated!

P.S. bonus points for helping me to add the size of the matrix as another parameter. Would this simply be cayley[x_,n_] := ..., and replacing 2 by n in the formula?

One Answer

Will this work for you?

cayley[x_] /;
    (SquareMatrixQ[x] && Det[IdentityMatrix[Length[x]] + x] != 0) :=
  Module[{i = IdentityMatrix[Length[x]]},
    (i - x).Inverse[i + x]]

Some tests

m = Partition[Range[16], 4];cayley[m]
{{-(13/9), -(4/3), -(2/9), 8/9}, {-(6/5), 1/5, -(2/5), 0}, 
 {2/45, -(4/15), 19/45, -(8/9)}, {58/45, 4/15, -(34/45), -(7/9)}}

Not a square matrix.

mx = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}}; cayley[mx]
cayley[{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}}]

$M+I$ not invertible.

my = -IdentityMatrix[4]; cayley[my] 
cayley[{{-1, 0, 0, 0}, {0, -1, 0, 0}, {0, 0, -1, 0}, {0, 0, 0, -1}}]

Correct answer by m_goldberg on May 24, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP