pseudinv.m

来自「(源代码)基于计算机的信号处理实践 栾晓明译」· M 代码 · 共 31 行

M
31
字号
function Ainv = pseudinv(A, r)
%PSEUDINV   Pseudo-inverse of rank r.
%--------
%   Usage:    Ainv = pseudinv(A, r)
%
%      produces the rank-r inverse of A, from the SVD of A.
%      Only r singular values are retained for the inverse
%      with the exception that singular values less than
%      MAX(SIZE(A)) * S(1) * EPS are discarded.
%      Ainv = pseudinv(A) uses all possible singular values.
%
% See also  SVD and PINV

%---------------------------------------------------------------
% copyright 1994, by C.S. Burrus, J.H. McClellan, A.V. Oppenheim,
% T.W. Parks, R.W. Schafer, & H.W. Schussler.  For use with the book
% "Computer-Based Exercises for Signal Processing Using MATLAB"
% (Prentice-Hall, 1994).
%---------------------------------------------------------------

[U,S,V] = svd(A);
S = diag(S);
keep = sum( S > (max(size(A)) * S(1) * eps) );
if (nargin == 1)
   r = keep;
else
   r = min( r, keep );
end
S = diag( ones(r,1) ./ S(1:r) );
Ainv = V(:,1:r) * S * U(:,1:r)';

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?