In many applications a matrix that is supposed to have a certain rank could appe
ID: 3799981 • Letter: I
Question
In many applications a matrix that is supposed to have a certain rank could appear to have a much larger rank because of inaccurate data or numerical errors. In this exercise we will explore how we can employ SVD to detect such an anomaly and how to partially correct it. In order to illustrate the ideas we will use an example. First we generate a matrix that we know has a certain rank. For instance with >> B = rand(2, 4) we can generate a 2 Times 4 matrix of rank two (check the rank with rank(B)). Now we will append two rows of zeros to B: >> Z = zeros(2, 4) >> C = [B;Z] Of course, the resulting matrix has rank two. Finally, we will multiply C with a random 4 Times 4 matrix from the left. This random matrix should have rank four, and then the resulting product A will be a 4 Times 4 with rank two (it is a good idea to think why, though you don't have answer this question as part of this homework) >> A = rand(4, 4)*C Now even a small perturbation of the entries of A should lend to a matrix whose rank is bigger than two. >> corruptA = A + 0.0001*[1 1 1 1; -1 -1 -1 -1; 1 2 3 4; -1 -2 -3 -4] Here corruptA is the matrix that has corrupted entries. In general we will not know exactly what the matrix A is. By computing the SVD of corruptA. can you "see" that it is close to a matrix of rank two? Explain your idea using this SVD Show how you can produce a rank two matrix that is not too far from the original matrix A. Present all jour computations.Explanation / Answer
import random random.seed(1234) def createRandomMatrix(n): maxVal = 1000 # I don't want to get Java / C++ into trouble matrix = [] for i in xrange(n): matrix.append([random.randint(0,maxVal) for el in xrange(n)]) return matrix def saveMatrix(matrixA, matrixB, filename): f = open(filename, 'w') for i, matrix in enumerate([matrixA, matrixB]): if i != 0: f.write(" ") for line in matrix: f.write(" ".join(map(str, line)) + " ") n = 3 matrixA = createRandomMatrix(n) matrixB = createRandomMatrix(n) saveMatrix(matrixA, matrixB, "2000.in")
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.