"Cory" wrote in message <email@example.com>... > Hi all, > > In some code I am writing, there will occasionally be some regularities in the problem that yield (essentially) singular matrices which I am supposed to use to solve a system of linear equations. As an illustrative example, I might have: > > A = [1 2 3 0 0; 4 5 6 0 0; 7 8 9 0 0; 0 0 0 1 -1; 0 0 0 -1 1] > b = [1; 2; 3; 0; 0] > > and I want to solve Ax = b. Of course there are multiple solutions. > > What is the easiest way for MATLAB to detect which rows are part of a non-singular portion so I can substitute an arbitrary value in for those equations. e.g. in the figure above, I would want to substitute an arbitrary equation for the 4th or 5th one. > > I can think of some awkward ways to do this, but would appreciate any advice on the most elegant way. > Shouldn't this be what singular value decomposition is for? [U,S,V] = svd(A); indx_true_null = find(diag(S)==0); indx_num_null = find(diag(S)<eps); % perhaps diag(S)/max(diag(S))<eps % In null: V(:,indx_true_null) % In numerical null: V(:,indx_num_null)
I guess you could use matlab's null function as well.