%
% Copyright (C) May/June 2005 by Henrik Pagenkopf
%
function Z = correct_PR(A, B, S, rA, cA, rB, cB) % computes Oh(size) many entries of S =approx.= A* B exactly.
%
% - cond: A,B,S are all square matrices of the same size >= 1 (type-safety of the ojbects used within this project).
% rA: row index of A etc. for choice of correcture position s.b.
%
sa = size(A);
sb = size(B);
sc = size(S);
if sa(1) >= 1 && sa(1)== sa(2) && sb(1)== sb(2) && sc(1)== sc(2) && sa(1)== sb(1) && sb(1)== sc(1) % => sa(2)== sb(2)== sc(2)
s = sa(1);
C = S;
for j = 1 : s % calculate the main diagonal entries of C == A* B exactly.
% sk = 0;
% for k = 1 : s % calc scalar product
%
% sk = sk + A(j,k)* B(k,j);
% end;
sk = A(j,:)* B(:,j);
C(j,j)= sk; % diagonal element
end; % for
for j = 1 : s % calculate same row as max<A> of C = A* B correctly.
C(rA,j)= A(rA,:)* B(:,j);
end; % for
for k = 1 : s % calculate same column as max<B> of C = A* B correctly.
C(k, cB)= A(k,:)* B(:,cB);
end; % for
Z = C; % <- result
else % error
end
% return.