function [M, b, N] = test(A, P) | % A is the matrix to be completed (if we do not know a_{ij}, then A(i, j)=1 | % P is a (0, 1)-matrix such that if we do not know a_{ij}, then P(i,j)=1. | % if we know a_{ij}, then P(i, j)=0. | % Use: [M, b, N] = test(A, P) | % M = M_A; b = b_A ; N = pseudo-inverse of the transpose of M_A | [n, m]=size(A); | n1 = (n2−n)/2; | n2 = sum(sum(P))/2; | n3 = n1−n2; | M = zeros(n3, n); | k = 1; | b = zeros(n3, 1); | for i=1:n | for j=i+1:n | If P(i, j)==0 | M(k, i)=1; M(k, j)=−1; | b(k)= log(A(i, j)); | k=k+1; | end | end | end | M=M
′
; | N=pinv(M
′
); | % Since there are numerical errors, a tolerance is used | if norm(M
′
*N*b−b) > 10(−10) | disp(‘There is no consistent completion’) | else | disp(‘There is consistent completion’) | end |
|