-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatrix_Lib.ads
99 lines (86 loc) · 4.69 KB
/
Matrix_Lib.ads
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
-------------------------------------------------------------------------------
-- --
-- Matrix Lib --
-- --
-- Matrix_Lib.ads --
-- --
-- SPEC --
-- --
-- Copyright (C) 1996 Ulrik Hørlyk Hjort --
-- --
-- Matrix Lib is free software; you can redistribute it --
-- and/or modify it under terms of the GNU General Public License --
-- as published by the Free Software Foundation; either version 2, --
-- or (at your option) any later version. --
-- Matrix Lib is distributed in the hope that it will be --
-- useful, but WITHOUT ANY WARRANTY; without even the implied warranty --
-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. --
-- See the GNU General Public License for more details. --
-- You should have received a copy of the GNU General --
-- Public License distributed with Yolk. If not, write to the Free --
-- Software Foundation, 51 Franklin Street, Fifth Floor, Boston, --
-- MA 02110 - 1301, USA. --
-- --
-------------------------------------------------------------------------------
package Matrix_Lib is
type Matrix is array (Natural range <>, Natural range <>) of Float;
type Column is array (Natural range <>) of Float;
----------------------------------------------------------------------------
--
----------------------------------------------------------------------------
function "*" (Left, Right : Matrix) return Matrix;
----------------------------------------------------------------------------
--
----------------------------------------------------------------------------
function "+" (Left, Right : Matrix) return Matrix;
----------------------------------------------------------------------------
--
----------------------------------------------------------------------------
function "-" (Left, Right : Matrix) return Matrix;
----------------------------------------------------------------------------
--
----------------------------------------------------------------------------
procedure Print(M : Matrix);
----------------------------------------------------------------------------
--
-- Solve the equation system AX=0
--
-- X is returned in Column
----------------------------------------------------------------------------
procedure Solve_Equation_System(A : in Matrix; Solution : out Column);
----------------------------------------------------------------------------
--
-- Calculate the determinant for the n*n matrix A by the Leibniz formula
-- as the sum of all permutations P over the set S in A'Range(1):
--
-- Det = SUM(parity(P) PROD(AiPi))
-- P in S i = 1 .. n
--
----------------------------------------------------------------------------
function Determinant(A : in Matrix) return Float;
----------------------------------------------------------------------------
--
-- Gaussian eliminination of the matrix A
--
----------------------------------------------------------------------------
procedure Gaussian_Elimination(A : in out Matrix);
-------------------------------------------------------------------------------
-- Inverse matrix I of A calculated by Gaussian elimination by solving the
-- equation system:
--
-- AX = Bi, where Bi is the i row in the identity matrix of same size as A
-- and B is size (A_row, 1)
--
-- For each solution Bi, Ii = Bi
--
--
-- Returns the inverse matrix to A
-------------------------------------------------------------------------------
function Get_Inverse_By_Gaussian_Elimination(A : Matrix) return Matrix;
-------------------------------------------------------------------------------
--
-- Calculate the inverse of matrix A
--
-------------------------------------------------------------------------------
function Get_Inverse(A : Matrix) return Matrix;
end Matrix_Lib;