Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -25,7 +25,7 @@ F printtable(data)
|
|||
print(row.map(cell -> ‘#<5’.format(cell)).join(‘ ’))
|
||||
|
||||
V m = [[3, 2], [2, 1]]
|
||||
L(i) 5
|
||||
L(i) 0.<5
|
||||
print("\n#.:".format(i))
|
||||
printtable(matrixExp(m, i))
|
||||
|
||||
|
|
|
|||
|
|
@ -1,90 +0,0 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
|
||||
procedure Test_Matrix is
|
||||
generic
|
||||
type Element is private;
|
||||
Zero : Element;
|
||||
One : Element;
|
||||
with function "+" (A, B : Element) return Element is <>;
|
||||
with function "*" (A, B : Element) return Element is <>;
|
||||
with function Image (X : Element) return String is <>;
|
||||
package Matrices is
|
||||
type Matrix is array (Integer range <>, Integer range <>) of Element;
|
||||
function "*" (A, B : Matrix) return Matrix;
|
||||
function "**" (A : Matrix; Power : Natural) return Matrix;
|
||||
procedure Put (A : Matrix);
|
||||
end Matrices;
|
||||
|
||||
package body Matrices is
|
||||
function "*" (A, B : Matrix) return Matrix is
|
||||
R : Matrix (A'Range (1), B'Range (2));
|
||||
Sum : Element := Zero;
|
||||
begin
|
||||
for I in R'Range (1) loop
|
||||
for J in R'Range (2) loop
|
||||
Sum := Zero;
|
||||
for K in A'Range (2) loop
|
||||
Sum := Sum + A (I, K) * B (K, J);
|
||||
end loop;
|
||||
R (I, J) := Sum;
|
||||
end loop;
|
||||
end loop;
|
||||
return R;
|
||||
end "*";
|
||||
|
||||
function "**" (A : Matrix; Power : Natural) return Matrix is
|
||||
begin
|
||||
if Power = 1 then
|
||||
return A;
|
||||
end if;
|
||||
declare
|
||||
R : Matrix (A'Range (1), A'Range (2)) := (others => (others => Zero));
|
||||
P : Matrix := A;
|
||||
E : Natural := Power;
|
||||
begin
|
||||
for I in P'Range (1) loop -- R is identity matrix
|
||||
R (I, I) := One;
|
||||
end loop;
|
||||
if E = 0 then
|
||||
return R;
|
||||
end if;
|
||||
loop
|
||||
if E mod 2 /= 0 then
|
||||
R := R * P;
|
||||
end if;
|
||||
E := E / 2;
|
||||
exit when E = 0;
|
||||
P := P * P;
|
||||
end loop;
|
||||
return R;
|
||||
end;
|
||||
end "**";
|
||||
|
||||
procedure Put (A : Matrix) is
|
||||
begin
|
||||
for I in A'Range (1) loop
|
||||
for J in A'Range (1) loop
|
||||
Put (Image (A (I, J)));
|
||||
end loop;
|
||||
New_Line;
|
||||
end loop;
|
||||
end Put;
|
||||
end Matrices;
|
||||
|
||||
package Integer_Matrices is new Matrices (Integer, 0, 1, Image => Integer'Image);
|
||||
use Integer_Matrices;
|
||||
|
||||
M : Matrix (1..2, 1..2) := ((3,2),(2,1));
|
||||
begin
|
||||
Put_Line ("M ="); Put (M);
|
||||
Put_Line ("M**0 ="); Put (M**0);
|
||||
Put_Line ("M**1 ="); Put (M**1);
|
||||
Put_Line ("M**2 ="); Put (M**2);
|
||||
Put_Line ("M*M ="); Put (M*M);
|
||||
Put_Line ("M**3 ="); Put (M**3);
|
||||
Put_Line ("M*M*M ="); Put (M*M*M);
|
||||
Put_Line ("M**4 ="); Put (M**4);
|
||||
Put_Line ("M*M*M*M ="); Put (M*M*M*M);
|
||||
Put_Line ("M**10 ="); Put (M**10);
|
||||
Put_Line ("M*M*M*M*M*M*M*M*M*M ="); Put (M*M*M*M*M*M*M*M*M*M);
|
||||
end Test_Matrix;
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with Ada.Complex_Text_IO; use Ada.Complex_Text_IO;
|
||||
with Ada.Numerics.Complex_Types; use Ada.Numerics.Complex_Types;
|
||||
with Ada.Numerics.Real_Arrays; use Ada.Numerics.Real_Arrays;
|
||||
with Ada.Numerics.Complex_Arrays; use Ada.Numerics.Complex_Arrays;
|
||||
with Ada.Numerics.Complex_Elementary_Functions; use Ada.Numerics.Complex_Elementary_Functions;
|
||||
|
||||
procedure Test_Matrix is
|
||||
function "**" (A : Complex_Matrix; Power : Complex) return Complex_Matrix is
|
||||
L : Real_Vector (A'Range (1));
|
||||
X : Complex_Matrix (A'Range (1), A'Range (2));
|
||||
R : Complex_Matrix (A'Range (1), A'Range (2));
|
||||
RL : Complex_Vector (A'Range (1));
|
||||
begin
|
||||
Eigensystem (A, L, X);
|
||||
for I in L'Range loop
|
||||
RL (I) := (L (I), 0.0) ** Power;
|
||||
end loop;
|
||||
for I in R'Range (1) loop
|
||||
for J in R'Range (2) loop
|
||||
declare
|
||||
Sum : Complex := (0.0, 0.0);
|
||||
begin
|
||||
for K in RL'Range (1) loop
|
||||
Sum := Sum + X (I, K) * RL (K) * X (J, K);
|
||||
end loop;
|
||||
R (I, J) := Sum;
|
||||
end;
|
||||
end loop;
|
||||
end loop;
|
||||
return R;
|
||||
end "**";
|
||||
procedure Put (A : Complex_Matrix) is
|
||||
begin
|
||||
for I in A'Range (1) loop
|
||||
for J in A'Range (2) loop
|
||||
Put (A (I, J));
|
||||
end loop;
|
||||
New_Line;
|
||||
end loop;
|
||||
end Put;
|
||||
M : Complex_Matrix (1..2, 1..2) := (((3.0,0.0),(2.0,1.0)),((2.0,-1.0),(1.0,0.0)));
|
||||
begin
|
||||
Put_Line ("M ="); Put (M);
|
||||
Put_Line ("M**0 ="); Put (M**(0.0,0.0));
|
||||
Put_Line ("M**1 ="); Put (M**(1.0,0.0));
|
||||
Put_Line ("M**0.5 ="); Put (M**(0.5,0.0));
|
||||
end Test_Matrix;
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
|
||||
with Ada.Numerics.Real_Arrays; use Ada.Numerics.Real_Arrays;
|
||||
|
||||
procedure Test_Matrix is
|
||||
procedure Put (A : Real_Matrix) is
|
||||
begin
|
||||
for I in A'Range (1) loop
|
||||
for J in A'Range (2) loop
|
||||
Put (" ");
|
||||
Put (A (I, J));
|
||||
end loop;
|
||||
New_Line;
|
||||
end loop;
|
||||
end Put;
|
||||
function "**" (A : Real_Matrix; Power : Integer) return Real_Matrix is
|
||||
L : Real_Vector (A'Range (1));
|
||||
X : Real_Matrix (A'Range (1), A'Range (2));
|
||||
R : Real_Matrix (A'Range (1), A'Range (2));
|
||||
RL : Real_Vector (A'Range (1));
|
||||
begin
|
||||
Eigensystem (A, L, X);
|
||||
for I in L'Range loop
|
||||
RL (I) := L (I) ** Power;
|
||||
end loop;
|
||||
for I in R'Range (1) loop
|
||||
for J in R'Range (2) loop
|
||||
declare
|
||||
Sum : Float := 0.0;
|
||||
begin
|
||||
for K in RL'Range loop
|
||||
Sum := Sum + X (I, K) * RL (K) * X (J, K);
|
||||
end loop;
|
||||
R (I, J) := Sum;
|
||||
end;
|
||||
end loop;
|
||||
end loop;
|
||||
return R;
|
||||
end "**";
|
||||
M : Real_Matrix (1..2, 1..2) := ((3.0, 2.0), (2.0, 1.0));
|
||||
begin
|
||||
Put_Line ("M ="); Put (M);
|
||||
Put_Line ("M**0 ="); Put (M**0);
|
||||
Put_Line ("M**1 ="); Put (M**1);
|
||||
Put_Line ("M**2 ="); Put (M**2);
|
||||
Put_Line ("M**3 ="); Put (M**3);
|
||||
Put_Line ("M**50 ="); Put (M**50);
|
||||
end Test_Matrix;
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
proc **(a, e) {
|
||||
// create result matrix of same dimensions
|
||||
var r:[a.domain] a.eltType;
|
||||
// and initialize to identity matrix
|
||||
forall ij in r.domain do
|
||||
r(ij) = if ij(1) == ij(2) then 1 else 0;
|
||||
|
||||
for 1..e do
|
||||
r *= a;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
var m:[1..3, 1..3] int;
|
||||
m(1,1) = 1; m(1,2) = 2; m(1,3) = 0;
|
||||
m(2,1) = 0; m(2,2) = 3; m(2,3) = 1;
|
||||
m(3,1) = 1; m(3,2) = 0; m(3,3) = 0;
|
||||
|
||||
config param n = 10;
|
||||
|
||||
for i in 0..n do {
|
||||
writeln("Order ", i);
|
||||
writeln(m ** i, "\n");
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
(define (dec x)
|
||||
(- x 1))
|
||||
|
||||
(define (halve x)
|
||||
(/ x 2))
|
||||
|
||||
(define (row*col row col)
|
||||
(apply + (map * row col)))
|
||||
|
||||
(define (matrix-multiply m1 m2)
|
||||
(map
|
||||
(lambda (row)
|
||||
(apply map (lambda col (row*col row col))
|
||||
m2))
|
||||
m1))
|
||||
|
||||
(define (matrix-exp mat exp)
|
||||
(cond ((= exp 1) mat)
|
||||
((even? exp) (square-matrix (matrix-exp mat (halve exp))))
|
||||
(else (matrix-multiply mat (matrix-exp mat (dec exp))))))
|
||||
|
||||
(define (square-matrix mat)
|
||||
(matrix-multiply mat mat))
|
||||
Loading…
Add table
Add a link
Reference in a new issue