From cb635eb860acd069c06374f4342a1e3ab83138e6 Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Sun, 14 Jun 2020 22:02:28 +0200 Subject: [PATCH] move python scripts --- {misc => euler/misc}/euler.py | 0 maxwell/misc/eigenvalues.py | 40 +++++++++++++++++++ {misc => maxwell/misc}/eigenvalues_rotated.py | 0 3 files changed, 40 insertions(+) rename {misc => euler/misc}/euler.py (100%) create mode 100755 maxwell/misc/eigenvalues.py rename {misc => maxwell/misc}/eigenvalues_rotated.py (100%) diff --git a/misc/euler.py b/euler/misc/euler.py similarity index 100% rename from misc/euler.py rename to euler/misc/euler.py diff --git a/maxwell/misc/eigenvalues.py b/maxwell/misc/eigenvalues.py new file mode 100755 index 0000000..04c41cc --- /dev/null +++ b/maxwell/misc/eigenvalues.py @@ -0,0 +1,40 @@ +#! /usr/bin/env python3 +import numpy as np + +A = np.array([[0, 0, 0], [0, 0, -1], [0, -1, 0]]) +B = np.array([[0, 1, 0], [1, 0, 0], [0, 0, 0]]) + + +def similarity_transform(matrix): + L, S = np.linalg.eig(matrix) + L = np.diag(L) + S = S.transpose() + assert np.allclose(np.matmul(S.transpose(), np.matmul(L, S)), matrix) + return L, S + + +def plusminus(matrix): + L, S = similarity_transform(matrix) + + def signed(op): + return 0.5 * np.matmul(S.transpose(), np.matmul(op(L, np.abs(L)), S)) + + plus = signed(np.add) + minus = signed(np.subtract) + + assert np.allclose(matrix, plus + minus) + return plus, minus + + +Aplus, Aminus = plusminus(A) +Bplus, Bminus = plusminus(B) + +print("A+") +print(Aplus) +print("A-") +print(Aminus) +print() +print("B+") +print(Bplus) +print("B-") +print(Bminus) diff --git a/misc/eigenvalues_rotated.py b/maxwell/misc/eigenvalues_rotated.py similarity index 100% rename from misc/eigenvalues_rotated.py rename to maxwell/misc/eigenvalues_rotated.py