This piece of code:
K = 3
N = 3
E = [np.reshape(np.array(i), (K, N)) for i in itertools.product([0, 1, -1], repeat = K*N)]
print 'E = ', E
Generates all possible E
matrices (dimensions 3x3) formed by 2 integers: 0
and 2
, e.g.:
...
array([[0, 2, 2],
[0, 0, 0],
[2, 0, 0]]), array([[0, 2, 2],
[0, 0, 0],
[2, 0, 2]]), array([[0, 2, 2],
[0, 0, 0],
[2, 2, 0]])
...
Given this matrix equation:
A_SC = E * A # Eqn. 1
where:
1) *
stands for the standard matrix multiplication (rows, columns)
2) A_SC
, E
and A
are 3x3 matrices,
3) E
are all the possible integer matrices generated by the above code.
4) A
is a known matrix:
A =np.array([[ 0.288155519353E+01, 0.000000000000E+00, 0.568733333333E+01],
[ -0.144077759676E+01, 0.249550000000E+01, 0.568733333333E+01],
[ -0.144077759676E+01, -0.249550000000E+01, 0.568733333333E+01]])
The A_SC
matrix can be represented as 3 rows vectors: a1_SC
, a2_SC
and a3_SC
:
|a1_SC|
A_SC = |a2_SC|
|a3_SC|
For a given E
matrix, there is a A_SC
matrix.
The following code:
1) loops over all possible E
matrices,
2) calculates the A_SC
matrix,
3) calculates the norm of a1_SC
, a2_SC
and a3_SC
,
4) and calculates the determinant of the E
matrix in that iteration:
for indx_E in E:
A_SC = np.dot(indx_E,A)
a1_SC = np.linalg.norm(A_SC[0])
a2_SC = np.linalg.norm(A_SC[1])
a3_SC = np.linalg.norm(A_SC[2])
det_indx_E = np.linalg.det(indx_E)
print 'a1_SC = ', a1_SC
print 'a2_SC = ', a2_SC
print 'a3_SC = ', a3_SC
print 'det_indx_E = ', det_indx_E
The goal would be to obtain all those A_SC
and E
matrices (Eqn. 1) for which the norm of these 3 rows vectors is the same and greater than 10,
norm(a1_SC) = norm(a2_SC) = norm(a3_SC) > 10
And at the same time, the determinant of E
has to be greater than 0.0
.
This condition can be expressed in this way: Just after this for
loop, we can write an if
loop:
tol_1 = 10
tol_2 = 0
for indx_E in E:
A_SC = np.dot(indx_E,A)
a1_SC = np.linalg.norm(A_SC[0])
a2_SC = np.linalg.norm(A_SC[1])
a3_SC = np.linalg.norm(A_SC[2])
det_indx_E = np.linalg.det(indx_E)
print 'a1_SC = ', a1_SC
print 'a2_SC = ', a2_SC
print 'a3_SC = ', a3_SC
print 'det_indx_E = ', det_indx_E
if a1_SC > tol_1\
and a2_SC > tol_1\
and a3_SC > tol_1\
and abs(a1_SC - a2_SC) == tol_2\
and abs(a1_SC - a3_SC) == tol_2\
and abs(a2_SC - a3_SC) == tol_2\
and det_indx_E > 0.0:
print 'A_SC = ', A_SC
print 'a1_SC = ', a1_SC
print 'a2_SC = ', a2_SC
print 'a3_SC = ', a3_SC
print 'det_indx_E = ', det_indx_E
# Now, which is the `E` matrix for this `A_SC` ?
# A_SC = E * A # Eqn. 1
# A_SC * inv(A) = E * A * inv(A) # Eqn. 2
#
# ------------------------------
# | A_SC * inv(A) = E # Eqn. 3 |
# ------------------------------
E_sol = np.dot(A_SC, np.linalg.inv(A))
print 'E_sol = ', E_sol
Just to be clear, this is the entire code:
A =np.array([[ 0.288155519353E+01, 0.000000000000E+00, 0.568733333333E+01],
[ -0.144077759676E+01, 0.249550000000E+01, 0.568733333333E+01],
[ -0.144077759676E+01, -0.249550000000E+01, 0.568733333333E+01]])
K = 3
N = 3
E = [np.reshape(np.array(i), (K, N)) for i in itertools.product([0, 1, -1], repeat = K*N)]
print 'type(E) = ', type(E)
print 'E = ', E
print 'len(E) = ', len(E)
tol_1 = 10
tol_2 = 0
for indx_E in E:
A_SC = np.dot(indx_E,A)
a1_SC = np.linalg.norm(A_SC[0])
a2_SC = np.linalg.norm(A_SC[1])
a3_SC = np.linalg.norm(A_SC[2])
det_indx_E = np.linalg.det(indx_E)
print 'a1_SC = ', a1_SC
print 'a2_SC = ', a2_SC
print 'a3_SC = ', a3_SC
print 'det_indx_E = ', det_indx_E
if a1_SC > tol_1\
and a2_SC > tol_1\
and a3_SC > tol_1\
and abs(a1_SC - a2_SC) == tol_2\
and abs(a1_SC - a3_SC) == tol_2\
and abs(a2_SC - a3_SC) == tol_2\
and det_indx_E > 0.0:
print 'A_SC = ', A_SC
print 'a1_SC = ', a1_SC
print 'a2_SC = ', a2_SC
print 'a3_SC = ', a3_SC
print 'det_indx_E = ', det_indx_E
# Now, which is the `E` matrix for this `A_SC` ?
# A_SC = E * A # Eqn. 1
# A_SC * inv(A) = E * A * inv(A) # Eqn. 2
#
# ------------------------------
# | A_SC * inv(A) = E # Eqn. 3 |
# ------------------------------
E_sol = np.dot(A_SC, np.linalg.inv(A))
print 'E_sol = ', E_sol
The problem is that no A_SC
(and therefore no E_sol
) are printed.
If you run this code, all norms and determinants are printed at each iteration, for example the following:
a1_SC = 12.7513326014
a2_SC = 12.7513326014
a3_SC = 12.7513326014
det_indx_E = 8.0
This would be a perfect candidate, because it satisfies
a1_SC = a2_SC = a3_SC = 12.7513326014 > 10.0
and
determinant > 0.0
However, no A_SC
(and therefore no E_sol
) are printed... why is this happening?
For example, this E
matrix:
2 0 0
E = 0 2 0
0 0 2
has det = 8.0
, and is a candidate, because it has:
a1_SC = a2_SC = a3_SC = 12.7513326014 > 10.0