Exercise 4.10.2

Answers

D = [ 0 9 25 9 0 16 2516 0 ]and d1 = [ 0 9 25 ], according to equation (4), we have G = [00 0 0 9 9 0925 ]

We solve the X using eigenvalue/eigenvectors of G as below.

import numpy as np 
def find_X(G): 
   v, L = np.linalg.eig(G) 
   print(EigenvaluesofG:\n, v) 
   print(EigenvectorsofG:\n, L) 
 
   n = G.shape[0] 
 
   W = np.identity(n) 
   for i in range(n): 
       # Check orthogonality 
       for j in range(n): 
           d = np.dot(L[:,i], L[:,j]) 
           print(Dotproductofcolumn, i, ’␣with␣column␣’, j, ’␣is:␣’, d) 
       W[i,i]= v[i] 
   Gk = np.matmul(np.matmul(L, W), L.transpose()) 
   print(TheGwitheigenvectors:\n, Gk) 
   X = np.matmul(np.sqrt(W), L.transpose()) 
   # This recovers G as well 
   Gc = np.matmul(X.transpose(), X) 
   print(ThecalculatedG:\n, Gc) 
   print(TheXis:\n, X) 
   return X 
 
G= np.array([[0, 0, 0], [0, 9, 9], [0, 9, 25]]) 
X = find_X(G)
Eigenvalues of G:
 [29.04159458  4.95840542  0.        ]
Eigenvectors of G:
 [[ 0.          0.          1.        ]
 [ 0.40965605  0.91224006  0.        ]
 [ 0.91224006 -0.40965605  0.        ]]
Dot product of column  0  with column  0  is:  1.0
Dot product of column  0  with column  1  is:  0.0
Dot product of column  0  with column  2  is:  0.0
Dot product of column  1  with column  0  is:  0.0
Dot product of column  1  with column  1  is:  1.0
Dot product of column  1  with column  2  is:  0.0
Dot product of column  2  with column  0  is:  0.0
Dot product of column  2  with column  1  is:  0.0
Dot product of column  2  with column  2  is:  1.0
The G with eigenvectors:
 [[ 0.  0.  0.]
 [ 0.  9.  9.]
 [ 0.  9. 25.]]
The calculated G:
 [[ 0.  0.  0.]
 [ 0.  9.  9.]
 [ 0.  9. 25.]]
The X is:
 [[ 0.          2.20764686  4.91608482]
 [ 0.          2.03132847 -0.91220068]
 [ 0.          0.          0.        ]]

G= np.array([[9, 9], [9, 25]]) 
L = np.linalg.cholesky(G) 
X = L.transpose() 
print(WefindanotherX:\n, X)
We find another X:
 [[3. 3.]
 [0. 4.]]

User profile picture
2020-03-20 00:00
Comments