Annotation of OpenXM_contrib/PHC/Ada/Math_Lib/Matrices/standard_random_matrices.adb, Revision 1.1
1.1 ! maekawa 1: with Standard_Random_Numbers; use Standard_Random_Numbers;
! 2: with Standard_Complex_Numbers; use Standard_Complex_Numbers;
! 3: with Standard_Natural_Vectors;
! 4: with Standard_Floating_Vectors;
! 5: with Standard_Complex_Vectors;
! 6: with Standard_Floating_QR_Decomposition; use Standard_Floating_QR_Decomposition;
! 7: with Standard_Complex_QR_Decomposition; use Standard_Complex_QR_Decomposition;
! 8:
! 9: package body Standard_Random_Matrices is
! 10:
! 11: function Random_Matrix ( n,m : natural; low,upp : integer )
! 12: return Standard_Integer_Matrices.Matrix is
! 13:
! 14: res : Standard_Integer_Matrices.Matrix(1..n,1..m);
! 15:
! 16: begin
! 17: for i in 1..n loop
! 18: for j in 1..m loop
! 19: res(i,j) := Random(low,upp);
! 20: end loop;
! 21: end loop;
! 22: return res;
! 23: end Random_Matrix;
! 24:
! 25: function Random_Matrix ( n,m : natural )
! 26: return Standard_Floating_Matrices.Matrix is
! 27:
! 28: res : Standard_Floating_Matrices.Matrix(1..n,1..m);
! 29:
! 30: begin
! 31: for i in 1..n loop
! 32: for j in 1..m loop
! 33: res(i,j) := Random;
! 34: end loop;
! 35: end loop;
! 36: return res;
! 37: end Random_Matrix;
! 38:
! 39: function Orthogonalize ( mat : Standard_Floating_Matrices.Matrix )
! 40: return Standard_Floating_Matrices.Matrix is
! 41:
! 42: n : constant natural := mat'length(1);
! 43: m : constant natural := mat'length(2);
! 44: res : Standard_Floating_Matrices.Matrix(1..n,1..m);
! 45: wrk : Standard_Floating_Matrices.Matrix(1..n,1..m);
! 46: bas : Standard_Floating_Matrices.Matrix(1..n,1..n);
! 47: qra : Standard_Floating_Vectors.Vector(1..n) := (1..n => 0.0);
! 48: pvt : Standard_Natural_Vectors.Vector(1..n) := (1..n => 0);
! 49:
! 50: begin
! 51: wrk := mat;
! 52: QRD(wrk,qra,pvt,false);
! 53: for i in wrk'range(1) loop
! 54: for j in wrk'range(2) loop
! 55: bas(i,j) := wrk(i,j);
! 56: end loop;
! 57: for j in m+1..n loop
! 58: bas(i,j) := 0.0;
! 59: end loop;
! 60: end loop;
! 61: Basis(bas,mat);
! 62: for i in res'range(1) loop
! 63: for j in res'range(2) loop
! 64: res(i,j) := bas(i,j);
! 65: end loop;
! 66: end loop;
! 67: return res;
! 68: end Orthogonalize;
! 69:
! 70: function Random_Orthogonal_Matrix
! 71: ( n,m : natural ) return Standard_Floating_Matrices.Matrix is
! 72:
! 73: res : Standard_Floating_Matrices.Matrix(1..n,1..m)
! 74: := Orthogonalize(Random_Matrix(n,m));
! 75:
! 76: begin
! 77: return res;
! 78: end Random_Orthogonal_Matrix;
! 79:
! 80: function Random_Matrix ( n,m : natural )
! 81: return Standard_Complex_Matrices.Matrix is
! 82:
! 83: res : Standard_Complex_Matrices.Matrix(1..n,1..m);
! 84:
! 85: begin
! 86: for i in 1..n loop
! 87: for j in 1..m loop
! 88: res(i,j) := Random;
! 89: end loop;
! 90: end loop;
! 91: return res;
! 92: end Random_Matrix;
! 93:
! 94: function Orthogonalize ( mat : Standard_Complex_Matrices.Matrix )
! 95: return Standard_Complex_Matrices.Matrix is
! 96:
! 97: n : constant natural := mat'length(1);
! 98: m : constant natural := mat'length(2);
! 99: res : Standard_Complex_Matrices.Matrix(1..n,1..m);
! 100: wrk : Standard_Complex_Matrices.Matrix(1..n,1..m);
! 101: bas : Standard_Complex_Matrices.Matrix(1..n,1..n);
! 102: qra : Standard_Complex_Vectors.Vector(1..n) := (1..n => Create(0.0));
! 103: pvt : Standard_Natural_Vectors.Vector(1..n) := (1..n => 0);
! 104:
! 105: begin
! 106: wrk := mat;
! 107: QRD(wrk,qra,pvt,false);
! 108: for i in wrk'range(1) loop
! 109: for j in wrk'range(2) loop
! 110: bas(i,j) := wrk(i,j);
! 111: end loop;
! 112: for j in m+1..n loop
! 113: bas(i,j) := Create(0.0);
! 114: end loop;
! 115: end loop;
! 116: Basis(bas,mat);
! 117: for i in res'range(1) loop
! 118: for j in res'range(2) loop
! 119: res(i,j) := bas(i,j);
! 120: end loop;
! 121: end loop;
! 122: return res;
! 123: end Orthogonalize;
! 124:
! 125: function Random_Orthogonal_Matrix
! 126: ( n,m : natural ) return Standard_Complex_Matrices.Matrix is
! 127:
! 128: res : Standard_Complex_Matrices.Matrix(1..n,1..m)
! 129: := Orthogonalize(Random_Matrix(n,m));
! 130:
! 131: begin
! 132: return res;
! 133: end Random_Orthogonal_Matrix;
! 134:
! 135: end Standard_Random_Matrices;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>