% 随机扩展Kaczmarz方法matlab代码实现
function [x, err, iter] = skaczmarz(A,b,x0,epsilon,n)
m = size(A,1);
x = x0;
err = zeros(n,1);
for iter=1:n
i = mod(iter-1,m)+1;
x = x+(b(i)-A(i,:)*x)*A(i,:)'/(A(i,:)*A(i,:)');
err(iter) = norm(A*x-b);
if err(iter) < epsilon
break;
end
end
end