
global A C k b x n lnFinv finv  result

disp("reading image"); fflush(1);
C=imread("comparagram.bmp");
imshow(C);
%C=[1,1,0,0;0,1,0,0;0,0,1,0;0,0,0,2];

n=size(C,1);
%A=zeros(n*n,n);
A=zeros(n,n);
lnFinv=zeros(n,1);
k=4;
%b=zeros(n*n,1);
b=zeros(n,1);

disp("creating system of equations"); fflush(1);
for i=1:n
  for j=1:n
%    A(i+n*(j-1), i) = A(i+n*(j-1), i) + C(i,j);
%    A(i+n*(j-1), j) = A(i+n*(j-1), j) - C(i,j);
%    b(i+n*(j-1))    = b(i+n*(j-1))    + C(i,j);
    A(i,i) = A(i,i) + C(i,j);
    A(i,j) = A(i,j) - C(i,j);
    b(i)   = b(i)   + C(i,j);
  end
  fprintf("%d\r",i); % show it
  fflush(1);
end
fprintf("\n");
b=b.*k;
% now A*lnFinv=b

%solve it
disp("solving..."); fflush(1);
lnFinv=A\b;
finv = e.^(lnFinv)
fflush(1);



