From: kovarik@mcmail.cis.McMaster.CA (Zdislav V. Kovarik) Subject: Re: pseudoinverse Date: 5 Feb 2001 03:14:52 -0500 Newsgroups: sci.math.num-analysis Summary: How does Matlab compute the Pseudo-inverse of a matrix? In article <3A7E4F27.C7AC4ACF@hotmail.com>, Elias Kyriakides wrote: :I know that MATLAB does have it, but it is a built-in function :and you cannot see the actual code. I need to write a code for :the pseudoinverse in C++. So if i have it in MATLAB i can :translate it into C++, but as i mentioned it is "hidden" in :MATLAB What version are you referring to? I typed "type pinv" and got the following - of course, you need svd which is a built-in function: function X = pinv(A,tol) %PINV Pseudoinverse. % X = PINV(A) produces a matrix X of the same dimensions % as A' so that A*X*A = A, X*A*X = X and A*X and X*A % are Hermitian. The computation is based on SVD(A) and any % singular values less than a tolerance are treated as zero. % The default tolerance is MAX(SIZE(A)) * NORM(A) * EPS. % % PINV(A,TOL) uses the tolerance TOL instead of the default. % % See also RANK. % Copyright (c) 1984-98 by The MathWorks, Inc. % $Revision: 5.7 $ $Date: 1997/11/21 23:38:41 $ [U,S,V] = svd(A,0); [m,n] = size(A); if m > 1, s = diag(S); elseif m == 1, s = S(1); else s = 0; end if nargin < 2 tol = max(m,n) * max(s) * eps; end r = sum(s > tol); if (r == 0) X = zeros(size(A')); else s = diag(ones(r,1)./s(1:r)); X = V(:,1:r)*s*U(:,1:r)'; end