
function x=solve_linear(A,b)

% Is A symmetric?
if norm(A-A') == 0
    flag=0.5;
end

if flag(1) == 0.5
    lambda=eig(A);
    if min(lambda) > 0
        flag=1;
    end
end


switch flag
    case 1
        L=chol(A,'lower');
        y=L\b;
        x=L'\y;
    otherwise
        [L,U,P]=lu(A);
        d=diag(U);
        detA_pm=prod(d);
        if prod(d) ~= 0
            c=P*b;
            y=L\c;
            x=U\y;
        else
            fprintf('\n \t SINGULAR MATRIX');
        end
end
