Salut à tous !

Je dois calculer le déterminant d'une matrice de rang n grâce à Lazarus et j'ai essayé de tirer quelque chose du programme du site. Mais mon programme me donne pas le bon déterminant... :/ Quelqu'un a une idée d'où je me suis plantée ? Surtout que le programme se lance 2 fois aussi...

Merci de votre aide !

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
PROGRAM determ (input,output);
 
 
TYPE
  tmat = array [1..10,1..10] of real;
 
VAR
  N : integer; { dimension de la matrice }
  det : real;    { déterminant }
  mat : tmat;    { matrice à calculer }
   I,J : integer ;
 
procedure sous_mat (A : tmat; var B : tmat; ind, N : integer);
{ on supprime la colonne 1 et la ligne ind pour avoir la s/mat de N-1 }
//A matrice de debut B matrice de fin
var J, I, L : integer;
 
begin
  L := 0;
  for I := 1 to N do
  begin
    if I <> ind then
  begin
       L := L + 1;
       for J := 2 to N do
         B[L,J - 1] := A[I,J]
  end
  end
end;                   
 
function detn (M : tmat; Nm : integer) : real; // M : matrice Nm:ordre de la matrice
{ On cherche l'ordre Nm de la sous matrice en fonction de l'ordre Nm-1 & determinant detn}
 
var 
Res : real;   // determinant
    mprim : tmat; // matrice intermédiaire 
    I, S: integer;  // I lignes J colonnes S signe des lignes
begin
  if Nm = 1
  then detn := M[1,1];
  if Nm = 2
  then detn:=M[1,1]*M[2,2]-M[2,1]*M[1,2];
  if Nm=3
  then detn:=M[1,1]*M[2,2]*M[3,3]+M[2,1]*M[3,2]*M[1,3]+M[1,2]*M[2,3]*M[3,1]
  -M[3,1]*M[2,2]*M[1,3]-M[3,2]*M[2,3]*M[1,1]-M[2,1]*M[1,2]*M[3,3]
  else
  begin
    Res := 0;
    S := -1;
    for I := 1 to Nm do
    begin
      sous_mat(M,mprim,I,Nm);
    S:= -S;    //change sign every lines
 
      Res := Res + (S * M[I,1] * detn(mprim,Nm - 1))
    end;
    detn := Res
  end
end;
 
BEGIN //principal program
 
        Write('Matrix order ');
        readln(N);
        for I:=1 to N do
        begin
                writeln('line ',I:2);
                for J:=1 to N do
                        readln(mat[I,J]);
        end;
 
        det:=detn(mat,N);//find the determinant
        Writeln('Determinant: ',det:2:1);
        readln;
END.