-
Notifications
You must be signed in to change notification settings - Fork 2
/
rkma.m
32 lines (27 loc) · 764 Bytes
/
rkma.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function [x,data] = rkma(A,V,b,p,maxiter)
%function rkma(A,V,b,p)
% Perform the randomized Kaczmarz with mismatched adjoint for the equation
% Ax=b using V' instead of A' as an adjoint. The i-th row is chosen with
% probability p(i).
% pretanspose for quicker row-extraction
AT = A';
VT = V';
x = zeros(size(A,2),1);
data.iter = zeros(1,floor(maxiter/size(A,1)));
data.iter(1) = 0;
data.x = zeros(size(A,2),floor(maxiter/size(A,1)));
data.x(:,1) = x;
l = 1;
for k=1:maxiter
i = sampling(p);
ai = AT(:,i);
vi = VT(:,i);
bi = b(i);
x = x - (ai'*x-bi)/(ai'*vi)*vi;
if mod(k,size(A,1)) == 0
l = l+1;
data.iter(l) = k;
data.x(:,l) = x;
fprintf('iter = %d, residual = %e\n',k,norm(A*x-b));
end
end