/usr/share/freemat/toolbox/matrix/pinv.m is in freemat-data 4.0-5build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | % PINV PINV Moore-Penrose Pseudoinverse
%
% Usage
%
% Calculates the Moore-Penrose pseudoinverse of a matrix.
% The general syntax for its use is
%
% y = pinv(A,tol)
%
% or for a default specification of the tolerance tol,
%
% y = pinv(A)
%
% For any m x n matrix A, the Moore-Penrose pseudoinverse
% is the unique n x m matrix B that satisfies the following
% four conditions
% - A B A = A
%
% - B A B = B
%
% - (A B)' = A B
%
% - (B A)' = B A
%
% Also, it is true that B y is the minimum norm, least squares
% solution to A x = y. The Moore-Penrose pseudoinverse is computed
% from the singular value decomposition of A, with singular values
% smaller than tol being treated as zeros. If tol is not specified
% then it is chosen as
%
% tol = max(size(A)) * norm(A) * teps(A).
%
% Copyright (c) 2005 Samit Basu
% Licensed under the GPL
function y = pinv(A,tol)
if (isempty(A))
y = A;
return;
end
[u,s,v] = svd(A,0);
if (~isset('tol'))
tol = max(size(A))*s(1,1)*teps(A);
end
sd = diag(s);
sd(sd > tol) = 1./(sd(sd > tol));
s = diag(sd);
y = v*s*u';
|