Commit 9c659cbb by EdwinMindcraft

### Fixed gauss_seidel.m

parent 80624d5f
 A = [1 2 3 4 5 ; 5 1 2 3 4 ; 4 5 1 2 3 ; 3 4 5 1 2 ; 2 3 4 5 1] Abis = [1 -1 -200 0 ; 0 1 100 -100 ; 0 1 101 -101 ; 0 0 0 100] b = [1 ; 1 ; 3 ; 4 ; 2] bbis = [1 ; 1 ; 2 ; 4] x = [0 ; 0 ; 0 ; 0 ; 0] xbis = [0 ; 0 ; 0 ; 0] n = size(b); delta = 10; %A = [1 2 3 4 5 ; 5 1 2 3 4 ; 4 5 1 2 3 ; 3 4 5 1 2 ; 2 3 4 5 1]; %Abis = [1 -1 -200 0 ; 0 1 100 -100 ; 0 1 101 -101 ; 0 0 0 100]; %b = [1 ; 1 ; 3 ; 4 ; 2]; %bbis = [1 ; 1 ; 2 ; 4]; %x = [0 ; 0 ; 0 ; 0 ; 0]; %xbis = [0 ; 0 ; 0 ; 0]; tol = 1e-10; cont = 0; delta = 10; A = [3 1;2 4]; b = [3;3]; x = [1;1]; n = size(b); while delta > tol & cont < 200 ref = x; for i = 1:n(1) tmp = 0; if j != i tmp = tmp + A(i,j)*x(j); end x(i) = (b(i) - tmp) / A(i,i) ; ref = x; for i = 1:n(1) tmp = 0; for j = 1:n(1) if j != i tmp = tmp + A(i,j)*x(j); end x(i) = (b(i) - tmp) / A(i,i); end delta = norm(ref - x); cont = cont + 1; end delta = norm(ref - x); cont = cont + 1; end fprintf('%f\n%f\n%f\n%f\n en %d boucles',x, cont); \ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment