gauss_seidel.m 613 Bytes
Newer Older
E-Girl-Mira's avatar
E-Girl-Mira committed
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
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; 

tol = 1e-10; 
cont = 0;

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) ;
    end
    
    delta = norm(ref - x);
    cont = cont + 1;

end

fprintf('%f\n%f\n%f\n%f\n en %d boucles',x, cont);