function [X,E]=verpinv(A)
gr=getround;
setround(0);
[m,n]=size(A);
X=repmat(infsup(NaN,NaN),n,m);
E.error='verpinv: none';
E.where='NaN';
E.value='NaN';
if (nargin~=1)||~isreal(A)||isintval(A)
E.error='verpinv: wrong data';
setround(gr); return
end
if issparse(A)
A=full(A);
end
[X1,Everpinvold]=verpinvold(A);
if isnan(X1.inf(1,1))
[X2,Everpinvviathinsvd]=verpinvviathinsvd(A);
else
X2=repmat(infsup(NaN,NaN),n,m);
end
if ~isnan(X1.inf(1,1))&&~isnan(X2.inf(1,1))
X=intersect(X1,X2);
setround(gr); return
else
if ~isnan(X1.inf(1,1))
X=X1;
setround(gr); return
end
if ~isnan(X2.inf(1,1))
X=X2;
setround(gr); return
end
clear E;
E=Everpinvold;
E(3)=Everpinvviathinsvd;
end
setround(gr);
function [X,E]=verpinvold(A)
gr=getround;
setround(0);
[m,n]=size(A);
X=repmat(infsup(NaN,NaN),n,m);
E.error='verpinvold: none';
E.where='NaN';
E.value='NaN';
if (nargin~=1)||~isreal(A)||isintval(A)
E.error='verpinvold: wrong data';
setround(gr); return
end
if issparse(A)
A=full(A);
end
[X1,Everpinvsimple]=verpinvsimple(A);
[X2,Evergreville]=vergreville(A);
if ~isnan(X1.inf(1,1))&&~isnan(X2.inf(1,1))
X=intersect(X1,X2);
setround(gr); return
else
if ~isnan(X1.inf(1,1))
X=X1;
setround(gr); return
end
if ~isnan(X2.inf(1,1))
X=X2;
setround(gr); return
end
clear E;
E(1)=Everpinvsimple;
E(2)=Evergreville;
end
setround(gr);
function [X,E]=verpinvsimple(A)
[m,n]=size(A);
E.error='verpinvsimple: none';
E.where='NaN';
E.value='NaN';
if m>=n
[X,Everpinvbasic]=verpinvbasic(A);
E=Everpinvbasic;
else
[X,Everpinvbasic]=(verpinvbasic(A'));
X=X';
E=Everpinvbasic;
end
function [X,E]=verpinvbasic(A)
[m,n]=size(A);
A=infsup(A,A);
X=repmat(infsup(NaN,NaN),n,m);
E.error='verpinvbasic: none';
E.where='NaN';
E.value='NaN';
if m<n
E.error='verpinvbasic: wrong data: m<n';
return
end
X1=inv(A'*A)*A';
I=eye(m,m); I=infsup(I,I);
O=zeros(n,n); O=infsup(O,O);
Onm=zeros(n,m); Onm=infsup(Onm,Onm);
A1=[A -I; O A'];
B1=[I; Onm];
X2=verifylss(A1,B1);
X2=X2(1:n,:);
if ~isnan(X1.inf(1,1))&&~isnan(X2.inf(1,1))
X=intersect(X1,X2);
return
else
if ~isnan(X1.inf(1,1))
X=X1;
return
end
if ~isnan(X2.inf(1,1))
X=X2;
return
end
E.error='verpinvbasic: none of the two applications of verifylss successful';
end
function [X,E]=vergreville(A)
[m,n]=size(A);
X=repmat(infsup(NaN,NaN),n,m);
E.error='vergreville: none';
E.where='NaN';
E.value='NaN';
[X1,Evergrevillebasic]=vergrevillebasic(A);
X2=(vergrevillebasic(A'))';
if ~isnan(X1.inf(1,1))&&~isnan(X2.inf(1,1))
X=intersect(X1,X2);
return
else
if ~isnan(X1.inf(1,1))
X=X1;
return
end
if ~isnan(X2.inf(1,1))
X=X2;
return
end
E=Evergrevillebasic;
end
function [X,E]=vergrevillebasic(A)
[m,n]=size(A);
E.error='vergrevillebasic: none';
E.where='NaN';
E.value='NaN';
A=infsup(A,A);
d=A(:,1);
if isequal(d,repmat(infsup(0,0),m,1))
X=d';
else
scal=d'*d;
if scal.inf>0
X=d'/scal;
else
X=repmat(infsup(NaN,NaN),n,m);
E.error='vergrevillebasic: division by zero';
E.where=['j = ',int2str(1)];
E.value=['scal = [',num2str(scal.inf),', ',num2str(scal.sup),']'];
return
end
end
for j=2:n
d=X*A(:,j);
c=A(:,j)-A(:,1:(j-1))*d;
if ~(any(c.sup<0)||any(c.inf>0))
X=repmat(infsup(NaN,NaN),n,m);
E.error='vergrevillebasic: neither c==0 nor c~=0 could be verified';
E.where=['j = ',int2str(j)];
E.value=['c = [',num2str(c.inf'),', ',num2str(c.sup'),']'];
return
end
scal=c'*c;
if scal.inf>0
bt=c'/(c'*c);
else
X=repmat(infsup(NaN,NaN),n,m);
E.error='vergrevillebasic: division by zero';
E.where=['j = ',int2str(j)];
E.value=['scal = [',num2str(scal.inf),', ',num2str(scal.sup),']'];
return
end
X=[X-d*bt; bt];
end
function [X,E]=verpinvviathinsvd(A)
[m,n]=size(A);
X=repmat(infsup(NaN,NaN),n,m);
E.error='verpinvviathinsvd: none';
E.where='NaN';
E.value='NaN';
[U,S,V,Everpinvviathinsvd]=verthinsvd(A);
if isnan(U.inf(1,1))
E=Everpinvviathinsvd;
return
end
sigma=diag(S);
r1=length(find(sigma.inf>0));
r2=length(find(sigma.sup>0));
if r1~=r2
r=infsup(r1,r2);
E.error='verpinvviathinsvd: verified rank could not be established';
E.value=['r = [',int2str(r.inf),', ',int2str(r.sup),']'];
end
r=r1;
if r>0
sigma=sigma(1:r);
sigma=1./sigma;
S(1:r,1:r)=diag(sigma);
X=V*S*U';
else
X=repmat(infsup(0,0),n,m);
end