X = pinv(A)
X = pinv(A,tol)
X = pinv(A) produces the Moore-Penrose pseudoinverse, which is a matrix X of the same dimensions as A' satisfying four conditions:
The computation is based onA*X*A = AX*A*X = XA*X is HermitianX*A is Hermitian
svd(A) and any singular values less than a tolerance are treated as zero. The default tolerance is
This tolerance can be overridden withtol = max(size(A))*norm(A)*eps
X = pinv(A,tol).
A is square and not singular, then pinv(A) is an expensive way to compute inv(A). If A is not square, or is square and singular, then inv(A) does not exist. In these cases, pinv(A) has some of, but not all, the properties of inv(A).
If A has more rows than columns and is not of full rank, then the overdetermined least squares problem
does not have a unique solution. Two of the infinitely many solutions areminimizenorm(A*x-b)
andx = pinv(A)*b
y = A\b
These two are distinguished by the facts that norm(x) is smaller than the norm of any other solution and that y has the fewest possible nonzero components. For example, the matrix generated by
A = magic(8); A = A(:,1:6)
is an 8-by-6 matrix which happens to have rank(A) = 3.
The right-hand side isA =64 2 3 61 60 69 55 54 12 13 5117 47 46 20 21 4340 26 27 37 36 3032 34 35 29 28 3841 23 22 44 45 1949 15 14 52 53 118 58 59 5 4 62
b = 260*ones(8,1),
The scale factor 260 is the 8-by-8 magic sum. With all eight columns, one solution tob =260260260260260260260260
A*x = b would be a vector of all 1s. With only six columns, the equations are still consistent, so a solution exists, but it is not all 1s. Since the matrix is rank deficient, there are infinitely many solutions. Two of them are
which isx = pinv(A)*b
andx =1.15381.46151.38461.38461.46151.1538
y = A\b
which is
Both of these are exact solutions in the sense thaty =3.00004.0000001.00000
norm(A*x-b) and norm(A*y-b) are on the order of roundoff error. The solution x is special because
norm(x) = 3.2817
is smaller than the norm of any other solution, including
norm(y) = 6.4807
On the other hand, the solution y is special because it has only three nonzero components.
inv,qr,rank,svd
(c) Copyright 1994 by The MathWorks, Inc.