clear all; close all; mat = [ 50,4.5, -23, 12, 1, 0, -1, 0; 1, 2, 3, 4, 5, 1, 0, 0; 2, 4, 6, 8, 10, 2, 0, 0]; % To compute the pseudoinverse in matlab I don't need to tranpose mat, % because matlab can do the SVD decomposition of matrices with more columns % than rows [U,S,V] = svd(mat); % pseudoinv = V * inv(S) * transpose(U); n_col = length(S(:,1)); n_fil = length(S(1,:)); max = n_fil; if (n_col < n_fil) max = n_col; end % As S is diagonal, que can compute its inverse by dividing inverting its % diagonal values for i = 1:max if (S(i,i) > 0.0000000001) S(i,i) = 1/S(i,i); else S(i,i) = 0; end end invS = transpose(S); pseudoinv = V * invS * transpose(U)