function [L, DX, DY, R] = simul_real_svd(X,Y) %This funtion does a %simultaneous real singular value decomposition of 2 matrices. %Given two real matrices X,Y of the same dimension, %it finds special (det=1) orthogonal matrices L and R %and real diagonal matrices DX, DY %such that L*DX*R'=X and L*DY*R'=Y %Reference: C.Eckart, G.Young, Bull. Am. Math. Soc. 45(1939)118 %LX'*X*RX = [DX00, Z01] % [Z10 , Z11] %LX'*Y*RX = G = [G00, Z01] % [Z10, G11] %[P00', Z10' ]*[DX00, Z01]*[P00, Z01 ] = DX %[Z01', LG11'] [Z10 , Z11] [Z10, RG11] %[P00', Z10' ]*[G00 , Z01]*[P00, Z01 ] = [DG00, Z01] = DY %[Z01', LG11'] [Z10 , G11] [Z10, RG11] [Z10, DG11] dim_U= rows(X); if(rows(X)!=rows(Y) | columns(X)!=columns(Y)) error("X and Y don't have the same dimensions"); endif [LX,DX,RX]=svd(X); %LX*DX*RX'=X %next find rank of X tol = dim_U*DX(1,1)*eps; rank_X = 1; j=2; done=false; while(jtol) rank_X = rank_X +1; else done=true; end j=j+1; end if(rank_X