function[x] = cramer(A,b)
% cramer(A, b) pro matici A a sloupcovy vektor b pocita reseni systemu A x = b Cramerovym pravidlem.

if nargin ~= 2
	error('Je nutno zadat matici a vektor!')
end

[r,s] = size(A);
b = b(:);

if r ~= s
    error('Matice A musi byt ctvercova!')
end

if length(b) ~= r
    error('Delka vektoru b a pocet radku matice A musi souhlasit!')
end

if det(A) == 0
    error('Matice A neni regularni!')
end

for i = 1:s
    AA = A;
    AA(:,i) = b;
    x(i) = det(AA) / det(A);
end

x = x(:);
end
