Homepage › Solution manuals › Gilbert Strang › Linear Algebra and Learning from Data › Exercise 4.10.2
Exercise 4.10.2
Answers
and , according to equation (4), we have
We solve the using eigenvalue/eigenvectors of as below.
import numpy as np def find_X(G): v, L = np.linalg.eig(G) print(’Eigenvalues␣of␣G:␣\n’, v) print(’Eigenvectors␣of␣G:␣\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(’Dot␣product␣of␣column␣’, i, ’␣with␣column␣’, j, ’␣is:␣’, d) W[i,i]= v[i] Gk = np.matmul(np.matmul(L, W), L.transpose()) print(’The␣G␣with␣eigenvectors:␣\n’, Gk) X = np.matmul(np.sqrt(W), L.transpose()) # This recovers G as well Gc = np.matmul(X.transpose(), X) print(’The␣calculated␣G:␣\n’, Gc) print(’The␣X␣is:␣\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(’We␣find␣another␣X:␣\n’, X)
We find another X: [[3. 3.] [0. 4.]]
2020-03-20 00:00