Code for block diagonalizing matrices  (distinct eigenvalues)

Definitions

In[1]:=

id = IdentityMatrix[3] ;

In[2]:=

χ[a_, λ_] := Factor[Det[a - λ id]]

In[3]:=

p[a_, λ_] := a . a - 2Re[λ] a + λ Conjugate[λ] id

In[4]:=

y[a_, λ_, x_] := -1/Im[λ] (a . x - Re[λ] x)

An Example

In[5]:=

a = {{5, -2, 2}, {2, 2, 1}, {-2, 3, 4}} ;

In[6]:=

χ[a, λ]

Out[6]=

-(-5 + λ) (13 - 6 λ + λ^2)

In[7]:=

Solve[%0, λ]

Out[7]=

{{λ3 - 2 }, {λ3 + 2 }, {λ5}}

In[8]:=

Eigenvalues[a]

Out[8]=

{5, 3 + 2 , 3 - 2 }

In[9]:=

p[a, Last[%]]

Out[9]=

{{0, 4, 4}, {0, 4, 4}, {0, 4, 4}}

NullSpace[%]

{{0, -1, 1}, {1, 0, 0}}

In[10]:=

y[a, 3 - 2I, {1, 0, 0}]

Out[10]=

{1, 1, -1}

In[11]:=

(a - (3 - 2I) id) . ({1, 0, 0} + I {1, 1, -1})

Out[11]=

{0, 0, 0}

In[12]:=

a . # - # . {{3, -2}, {2, 3}} &[Transpose[{{1, 0, 0}, {1, 1, -1}}]]

Out[12]=

{{0, 0}, {0, 0}, {0, 0}}

In[13]:=

NullSpace[a - 5 id]

Out[13]=

{{1, 1, 1}}

In[14]:=

Inverse[#] . a . #&[Transpose[{{1, 0, 0}, {1, 1, -1}, {1, 1, 1}}]]

Out[14]=

{{3, -2, 0}, {2, 3, 0}, {0, 0, 5}}

In[15]:=

MatrixForm[%]

Out[15]//MatrixForm=

( 3    -2   0  )            2    3    0            0    0    5

In[16]:=

y[a, 3 - 2I, {0, -1, 1}]

Out[16]=

{2, 1, -1}

In[17]:=

MatrixForm[Inverse[#] . a . #&[Transpose[{{0, -1, 1}, {2, 1, -1}, {1, 1, 1}}]]]

Out[17]//MatrixForm=

( 3    -2   0  )            2    3    0            0    0    5

In[18]:=

{{0, -1, 1}, {2, 1, -1}, {1, 1, 1}}//Det

Out[18]=

4

Getting there using built-in functions

In[19]:=

Eigensystem[a]

Out[19]=

{{5, 3 + 2 , 3 - 2 }, {{1, 1, 1}, {-1 - , -1, 1}, {-1 + , -1, 1}}}

In[20]:=

Inverse[#] . a . #&[Transpose[{Re[%〚2, 3〛], Im[%〚2, 3〛], %〚2, 1〛}]]

Out[20]=

{{3, -2, 0}, {2, 3, 0}, {0, 0, 5}}

In[21]:=

Inverse[#] . a . #&[Transpose[{%%〚2, 1〛, Re[%%〚2, 2〛], Im[%%〚2, 2〛]}]]//MatrixForm

Out[21]//MatrixForm=

( 5    0    0  )            0    3    2            0    -2   3

Another Example

In[22]:=

a = {{5, 0, -2}, {8, 7, -12}, {6, 4, -7}} ;

χ[a, λ]

-(-3 + λ) (5 - 2 λ + λ^2)

In[23]:=

Eigenvalues[a]

Out[23]=

{3, 1 + 2 , 1 - 2 }

p[a, Last[%]]

{{8, -8, 8}, {8, -8, 8}, {8, -8, 8}}

NullSpace[%]

{{-1, 0, 1}, {1, 1, 0}}

y[a, 1 + 2I, {-1, 0, 1}]

{3, 10, 7}

(a - (1 + 2I) id) . ({-1, 0, 1} + I {3, 10, 7})

a . # - # . {{1, 2}, {-2, 1}} &[Transpose[{{-1, 0, 1}, {3, 10, 7}}]]

NullSpace[a - 3 id]

{{1, 1, 1}}

In[24]:=

Inverse[#] . a . #&[Transpose[{{-1, 0, 1}, {3, 10, 7}, {1, 1, 1}}]]

Out[24]=

{{1, 2, 0}, {-2, 1, 0}, {0, 0, 3}}

In[25]:=

MatrixExp[t %]

Out[25]=

{{^t Cos[2 t], ^t Sin[2 t], 0}, {-^t Sin[2 t], ^t Cos[2 t], 0}, {0, 0, ^(3 t)}}

In[26]:=

MatrixForm[%]

Out[26]//MatrixForm=

(         t                     t                                 )            ...                                 3 t           0                     0                     

In[27]:=

# . % . Inverse[#] &[Transpose[{{-1, 0, 1}, {3, 10, 7}, {1, 1, 1}}]]

Out[27]=

{{^(3 t) - 3/10 (-^t Cos[2 t] - 3 ^t Sin[2 t]) + 1/10 (-3 ^t C ... 63309;^t Cos[2 t] - 7 ^t Sin[2 t]) + 1/10 (-7 ^t Cos[2 t] - ^t Sin[2 t])}}

In[28]:=

Factor[MatrixExp[t a] - %]

Out[28]=

{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}

In[29]:=

MatrixExp[t a]

Out[29]=

{{^t (^(2 t) + Sin[2 t]), -^t (^(2 t) - Cos[2 t] - Sin[2 t]),  ... , -^t (^(2 t) - Cos[2 t] - 3 Sin[2 t]), ^t (^(2 t) - 5 Sin[2 t])}}

In[30]:=

Factor[%]

Out[30]=

{{^t (^(2 t) + Sin[2 t]), -^t (^(2 t) - Cos[2 t] - Sin[2 t]),  ... , -^t (^(2 t) - Cos[2 t] - 3 Sin[2 t]), ^t (^(2 t) - 5 Sin[2 t])}}

In[31]:=

Expand[%]

Out[31]=

{{^(3 t) + ^t Sin[2 t], -^(3 t) + ^t Cos[2 t] + ^t Sin ... 309;^(3 t) + ^t Cos[2 t] + 3 ^t Sin[2 t], ^(3 t) - 5 ^t Sin[2 t]}}

In[32]:=

MatrixForm[%]

Out[32]//MatrixForm=

(         3 t           t                                               3 t            ...    -    +   Cos[2 t] + 3   Sin[2 t]         - 5   Sin[2 t]

In[43]:=

Array[Random[Integer, {-10, 10}] &, {2, 2}]

Out[43]=

{{-1, 0}, {-5, 1}}

In[44]:=

Eigenvalues[%]

Out[44]=

{-1, 1}

In[33]:=

Array[Random[Real, {-10, 10}] &, {8, 8}]

Out[33]=

RowBox[{{, RowBox[{RowBox[{{, RowBox[{7.93304, ,, RowBox[{-, 6.77766}], ,, RowBox[{-, 0.681747 ... , 1.75026, ,, RowBox[{-, 5.62135}], ,, RowBox[{-, 0.827803}], ,, 7.02845, ,, 2.21652}], }}]}], }}]

In[34]:=

MatrixExp[t %]

Out[34]=

RowBox[{{, RowBox[{RowBox[{{, RowBox[{RowBox[{RowBox[{, ^, RowBox[{(, RowBox[{RowBox[{ ... ox[{12.55,  , t}], )}]}],  , RowBox[{Sin, [, RowBox[{10.2943,  , t}], ]}]}]}], )}]}]}], }}]}], }}]

In[35]:=

Expand[%]

In[36]:=

Chop[%]

Out[36]=

RowBox[{{, RowBox[{RowBox[{{, RowBox[{RowBox[{RowBox[{0.324998,  , RowBox[{, ^, RowBox ... ox[{-, 11.4342}],  , t}], )}]}],  , RowBox[{Sin, [, RowBox[{10.2943,  , t}], ]}]}]}]}], }}]}], }}]

Export :: nodir : Directory /home/math/faculty/lewis/public_html/Math106/HTMLNotebooks/MatExp/ does not exist. More…

Export :: nodir : Directory /home/math/faculty/lewis/public_html/Math106/HTMLNotebooks/MatExp/ does not exist. More…

Export :: nodir : Directory /home/math/faculty/lewis/public_html/Math106/NotebooksHTML/MatExp/ does not exist. More…

General :: stop : Further output of Export :: nodir will be suppressed during this calculation. More…


Created by Mathematica  (November 23, 2003)