clc;clear;close all;
matrix=load('matrix2.mat');
matrix=matrix.matrix;
matrix_original=matrix;
matrix=round(matrix);
result=log10(abs(det(matrix)))/log10(2);

[m,n]=size(matrix);
matriz_old=matrix;
for j=1:m-1
    for i=j+1:m
        while(matrix(i,j)~=0)
            old=matrix(i,j);
            temp1=abs(matrix(i,j));
            temp2=abs(matrix(j,j));
            k=floor(log2(temp1))- floor(log2(temp2));
            if sign(matrix(i,j)) ==sign(matrix(j,j))
                matrix(i,:)=matrix(i,:)-fix((2^k)*matrix(j,:));%%%%Se debe de aproximar a 0 no al menor
            else
                matrix(i,:)=matrix(i,:)+fix((2^k)*matrix(j,:));
            end
            new=matrix(i,j);
        end
    end
end

resultado=log10(abs(det(matrix)))/log10(2);

new_matrix=matrix;

matrix=matriz_old;

for j=1:m-1
    for i=j+1:m
        k=matrix(i,j)/matrix(j,j);
        matrix(i,:)= matrix(i,:)-k*matrix(j,:);
    end
end

real_matrix=matrix;

matrix=matriz_old;

for j=1:m-1
    for i=j+1:m
        k=round(matrix(i,j)/matrix(j,j));
        matrix(i,:)= matrix(i,:)-k*matrix(j,:);
    end
end

div_matrix=matrix;

new=(abs((new_matrix-real_matrix)./real_matrix))*100;
old=(abs((div_matrix-real_matrix)./real_matrix))*100;

cadena=zeros([1 m]);
for i=2:m
    cadena(1,i)=new(i,i);
end
error_mean=mean(cadena);
error_max=max(cadena);
