Advertisement
dxvmxnd

Untitled

Mar 13th, 2024
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. unction Determinant(Matrix : TMatrix) : Integer;
  2. var
  3. Size: Integer;
  4. Minor: TMatrix;
  5. i, j, k: Integer;
  6. Sign: Integer;
  7. begin
  8. Size := Length(Matrix);
  9.  
  10. if Size = 1 then
  11. Result := Matrix[0, 0]
  12. else
  13. begin
  14. Result := 0;
  15. Sign := 1;
  16.  
  17. for k := 0 to Size - 1 do
  18. begin
  19. SetLength(Minor, Size - 1, Size - 1);
  20. for i := 1 to Size - 1 do
  21. for j := 0 to Size - 1 do
  22. begin
  23. if j < k then
  24. Minor[i - 1, j] := Matrix[i, j]
  25. else if j > k then
  26. Minor[i - 1, j - 1] := Matrix[i, j];
  27. end;
  28. Result := Result + Sign * Matrix[0, k] * Determinant(Minor);
  29.  
  30. Sign := -Sign;
  31. end;
  32. end;
  33. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement