File:Diagonalization as rotation.gif

Summary

Description
English: You can visualize a matrix diagonalization as a rotation of your axis to align them with the matrix eigenvectors.
Date
Source https://twitter.com/j_bertolotti/status/1192396841381515264
Author Jacopo Bertolotti
Permission
(Reusing this file)
https://twitter.com/j_bertolotti/status/1030470604418428929
Camera location52° 44′ 24.84″ N, 8° 11′ 40.65″ E Kartographer map based on OpenStreetMap.View this and other nearby images on: OpenStreetMapinfo
Category:Files with coordinates missing SDC location of creation (52° N, 8° E)

Mathematica 11.0 code

m = RandomReal[{-10, 10}, {3, 3}];
m = Round[(m + Transpose[m])/2, 0.01];
\[Lambda] = Eigenvalues[m];
\[Psi] = Eigenvectors[m];

angle[u_, v_] := ArcCos[u.v/(Norm[u] Norm[v])];
xyz = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
\[Alpha]1 = \[Alpha] /. NMinimize[Norm[EulerMatrix[{\[Alpha], 0, 0}].xyz[[2]] - Cross[{0, 0, 1}, \[Psi][[3]]]/Norm[Cross[{0, 0, 1}, \[Psi][[3]]]] ], \[Alpha]][[2]];(*rotate y in the plane perpendicular to Subscript[\[Psi], z]*)
\[Beta]1 = angle[{0, 0, 1}, \[Psi][[3]]];
\[Gamma]1 = -angle[Cross[{0, 0, 1}, \[Psi][[3]]], \[Psi][[2]]];

p1 = Table[
   Grid[{{
      PaddedForm[MatrixForm[Inverse[EulerMatrix[{\[Alpha], 0, 0}]].m.EulerMatrix[{\[Alpha], 0, 0}] ], {3, 2}], Graphics3D[{Gray, Table[Arrow[{{0, 0, 0}, xyz[[j]]}], {j, 1, 3}], Sphere[{0, 0, 0}, 0.1]
        , Black, Table[Arrow[{{0, 0, 0}, EulerMatrix[{\[Alpha], 0, 0}].xyz[[j]]}], {j, 1, 3}] }, Boxed -> False, PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}]
      }}]
   , {\[Alpha], 0, \[Alpha]1, \[Alpha]1/40}];
p2 = Table[
   Grid[{{
      PaddedForm[MatrixForm[Round[Inverse[EulerMatrix[{\[Alpha]1, \[Beta], 0}]].m.EulerMatrix[{\[Alpha]1, \[Beta], 0}], 0.01] ], {3,2}], Graphics3D[{Gray, Table[Arrow[{{0, 0, 0}, xyz[[j]]}], {j, 1, 3}], 
        Sphere[{0, 0, 0}, 0.1], Black, Table[Arrow[{{0, 0, 0}, EulerMatrix[{\[Alpha]1, \[Beta], 0}].xyz[[j]]}], {j, 1, 3}]
        }, Boxed -> False, PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}]
      }}]
   , {\[Beta], 0, \[Beta]1, \[Beta]1/40}];
p3 = Table[
   Grid[{{
      PaddedForm[MatrixForm[Round[Inverse[EulerMatrix[{\[Alpha]1, \[Beta]1, \[Gamma]}]].m.EulerMatrix[{\[Alpha]1, \[Beta]1, \[Gamma]}], 0.01] ], {3, 2}], Graphics3D[{Gray, Table[Arrow[{{0, 0, 0}, xyz[[j]]}], {j, 1, 3}], Sphere[{0, 0, 0}, 0.1], Black, Table[Arrow[{{0, 0, 0}, EulerMatrix[{\[Alpha]1, \[Beta]1, \[Gamma]}].xyz[[j]]}], {j, 1, 3}]
        }, Boxed -> False, PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}]
      }}]
   , {\[Gamma], 0, \[Gamma]1, \[Gamma]1/40}];
ListAnimate[Join[p1, p2, p3, Table[p3[[-1]], 30]]]

Licensing

I, the copyright holder of this work, hereby publish it under the following license:
Creative Commons CC-Zero This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication.
The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.

Category:CC-Zero#Diagonalization%20as%20rotation.gifCategory:Self-published work
Category:Matrices Category:Eigenvalue problems Category:Matrix diagonalization Category:Rotation animations Category:Images with Mathematica source code Category:Animated GIF files
Category:Animated GIF files Category:CC-Zero Category:Eigenvalue problems Category:Files with coordinates missing SDC location of creation (52° N, 8° E) Category:Images with Mathematica source code Category:Matrices Category:Matrix diagonalization Category:Rotation animations Category:Self-published work