%%
clear
close all
clc


n = 40;
A = 2*eye(n)-diag(ones(n-1,1),-1)-diag(ones(n-1,1),1);
b = randn(n,1);

D = diag(diag(A));
U = triu(A)-diag(diag(A));
L = (triu(A')-diag(diag(A)))';

% A-(L+D+U)


x = randn(n,1);
for kk=1:10000
    x = D\(b-(L+U)*x);
%     hold on, plot(kk,x(1),'b.','MarkerSize',20)
%     drawnow
end
    
norm(A*x-b)/n

xs = A\b;
norm(A*xs-b)/n