Bonjour,
J'essaye d'implementer un pivot de gauss en java. L'entree de l'algorithme est matrice[][] contenant la matrice du systeme et conf[] le vecteur contenant les elements à droite du syteme. J'ai comparé ce que me renvois la fonction gauss() avec le résultat donné par SAGE, mais ca ne correspond pas. Toutes les opéarations doivent se faire avec un modulo donné, ici j'ai seulement géré le cas du modulo 2. De plus, si toutes les opérations se font modulo 2, les données initiales ne contiendront que des 0 ou 1.
gauss() renvoit la matrice triangulaire, substitution récupéré les solutions.

Voici mon programme :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
 
public void gauss(){ 
 
int libre = 0;
for(int c = 0 ; c < matrice.length ; c++){
    int pivot = getPivot(c,libre);
    if( pivot == -1){
    continue;
    }
    swapDouble(pivot,libre);
    swapSimple(pivot,libre);
 
    for(int r = libre+1 ; r < matrice.length; r++){
    if(matrice[r][c] !=0){
        for(int l = c ; l<matrice.length ; l++){
        matrice[r][l] = (matrice[r][l]+matrice[libre][l])%this.nbEtat;
        }
        conf[r] = (conf[r]+conf[libre])%this.nbEtat;
    }
    }
    libre++;
}   
}
 
public void swapDouble ( int i , int j){  
 
for(int k = 0 ; k < matrice.length ; k++){
    int tmp = matrice[i][k];
    matrice[i][k] = matrice[j][k];
    matrice[j][k] = tmp;
}
} 
 
public void swapSimple( int i, int j){ 
int tmp = conf[i];
conf[i] = conf[j];
conf[j] = tmp;
}
 
public int[] substitution() throws Exception{   
 
int [] sol = new int [matrice.length];
for(int i = 0 ; i <sol.length ; i++){
    sol[i]= 0;
}
 
for(int ligne = matrice.length-1; ligne >= 0 ; ligne--){ 
    int pivot = -1;
 
    for(int col = 0; col < matrice.length ; col++){
    if(matrice[ligne][col] != 0){
        pivot = col;
        break;
    }
    }
 
    if(pivot == -1 && conf[ligne] != 0){
    throw new Exception();
    }
    else{
    sol[ligne] = conf[ligne];
    for(int p = pivot ; p < matrice.length ; p++){
        sol[ligne] = (sol[ligne]+ matrice[ligne][p])%this.nbEtat;
    }
    }
 
}
 
return sol;
}
 
public int getPivot(int colonne , int depart){  
for( int i = depart; i < matrice.length ; i++){
    if(matrice[i][colonne] == 1){
    return i;
    }
}
return -1; 
}