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