function x = choleskySolver(R,b)
% x = choleskySolver(R,b) solves A x = b
%     R has te be generated by R=cholesky(A)

[n,m] = size(R);
if (n ~= length(b))   
  error ('choleskySover: matrix and vector doe not have same dimension')
end%if

% forward substitution of R' y = b
y = zeros(size(b));
y(1) = b(1);
for k = 2:n
  y(k) = b(k);
  for j = 1:k-1  y(k) = y(k) - R(j,k)*y(j); end%for
end%for

% solve diagonal system
for k = 1:n y(k) = y(k)/R(k,k);end%for

% forward substitution of R' y = b
x = zeros(size(b));
x(n) = y(n);
for k = 1:n-1
  x(n-k) = y(n-k);
  for j = n-k+1:n  x(n-k) = x(n-k) - R(n-k,j)*x(j); end%for
end%for
