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.35473279 0.66569612 0.37851704]
[0.66569612 0.49881953 0.34467884]
[0.37851704 0.34467884 0.91026962]]
KM(ε) =
[0.35473279 0.49881953 0.91026962 0.48744949 0.53530393 0.94143648]
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 =
[[3.43130579 1.02195245 1.50621265 2.46912517 2.82552258 2.01149492]
[1.02195245 2.06658272 0.53164441 0.71906412 1.37138385 1.14551359]
[1.50621265 0.53164441 2.24862943 1.51201039 1.66657135 1.17429339]
[2.46912517 0.71906412 1.51201039 3.87954039 2.73599011 1.91678353]
[2.82552258 1.37138385 1.66657135 2.73599011 4.52891943 2.49894942]
[2.01149492 1.14551359 1.17429339 1.91678353 2.49894942 2.882882 ]]
c =
[[[[3.43130579 1.4223417 1.99794618]
[1.4223417 1.02195245 1.74593515]
[1.99794618 1.74593515 1.50621265]]
[[1.4223417 1.441441 1.24947471]
[1.441441 0.81000043 0.95839176]
[1.24947471 0.95839176 0.83035082]]
[[1.99794618 1.24947471 2.26445972]
[1.24947471 0.96971482 1.36799506]
[2.26445972 1.36799506 1.1784439 ]]]
[[[1.4223417 1.441441 1.24947471]
[1.441441 0.81000043 0.95839176]
[1.24947471 0.95839176 0.83035082]]
[[1.02195245 0.81000043 0.96971482]
[0.81000043 2.06658272 0.50845512]
[0.96971482 0.50845512 0.53164441]]
[[1.74593515 0.95839176 1.36799506]
[0.95839176 0.50845512 1.93977019]
[1.36799506 1.93977019 1.0691528 ]]]
[[[1.99794618 1.24947471 2.26445972]
[1.24947471 0.96971482 1.36799506]
[2.26445972 1.36799506 1.1784439 ]]
[[1.74593515 0.95839176 1.36799506]
[0.95839176 0.50845512 1.93977019]
[1.36799506 1.93977019 1.0691528 ]]
[[1.50621265 0.83035082 1.1784439 ]
[0.83035082 0.53164441 1.0691528 ]
[1.1784439 1.0691528 2.24862943]]]]
\(\,\)