import numpy as np
from echoes import *
import math, random
np.set_printoptions(precision=8, suppress=True)
# to display only 8 significant digits of array components1 Kelvin-Mandel notation
A symmetric \(3×3\) second-order matrix can be transformed in a vector of \(\R^6\) by the function KM consistently with (A.14). The inverse is done by invKM.
α = np.random.rand(3, 3) ; ε = (α+α.T)/2
print("ε =\n",ε)
print("KM(ε) =\n",KM(ε))
assert np.allclose(invKM(KM(ε)), ε), "error"ε =
[[0.69709813 0.53506694 0.32442103]
[0.53506694 0.94504071 0.77793264]
[0.32442103 0.77793264 0.3123916 ]]
KM(ε) =
[0.69709813 0.94504071 0.3123916 1.10016289 0.45880062 0.75669892]
Given a \(3×3×3×3\) array c (of type numpy.ndarray) satisfying major and minor symmetries (see Section A.2), the corresponding \(6×6\) matrix C obtained by Kelvin-Mandel transform is calculated by C = KM(c). Conversely, if C is a positive definite matrix, c is calculated by c = invKM(C).
A = np.random.rand(6,6)
C = A.T.dot(A) + np.eye(6) # generation of an arbitrary positive definite matrix
c = invKM(C)
print("C =\n",C)
print("c =\n",c)
assert np.allclose(KM(c), C), "error: KM(c) should be equal to C"C =
[[2.8344474 1.34244392 1.68007537 1.99254191 1.60339856 1.25473437]
[1.34244392 2.80416731 1.9010566 1.6950774 1.97903622 0.90911807]
[1.68007537 1.9010566 3.18344589 2.10720072 2.31111208 1.38175589]
[1.99254191 1.6950774 2.10720072 3.43130947 2.12506884 1.71139854]
[1.60339856 1.97903622 2.31111208 2.12506884 3.68201779 1.60227351]
[1.25473437 0.90911807 1.38175589 1.71139854 1.60227351 2.64520247]]
c =
[[[[2.8344474 0.88723118 1.133774 ]
[0.88723118 1.34244392 1.4089399 ]
[1.133774 1.4089399 1.68007537]]
[[0.88723118 1.32260124 0.80113676]
[1.32260124 0.64284356 0.85569927]
[0.80113676 0.85569927 0.97704896]]
[[1.133774 0.80113676 1.8410089 ]
[0.80113676 1.39938993 1.06253442]
[1.8410089 1.06253442 1.63420302]]]
[[[0.88723118 1.32260124 0.80113676]
[1.32260124 0.64284356 0.85569927]
[0.80113676 0.85569927 0.97704896]]
[[1.34244392 0.64284356 1.39938993]
[0.64284356 2.80416731 1.19860072]
[1.39938993 1.19860072 1.9010566 ]]
[[1.4089399 0.85569927 1.06253442]
[0.85569927 1.19860072 1.71565474]
[1.06253442 1.71565474 1.49001592]]]
[[[1.133774 0.80113676 1.8410089 ]
[0.80113676 1.39938993 1.06253442]
[1.8410089 1.06253442 1.63420302]]
[[1.4089399 0.85569927 1.06253442]
[0.85569927 1.19860072 1.71565474]
[1.06253442 1.71565474 1.49001592]]
[[1.68007537 0.97704896 1.63420302]
[0.97704896 1.9010566 1.49001592]
[1.63420302 1.49001592 3.18344589]]]]
\(\,\)