with text_io,integer_io; use text_io,integer_io; with Standard_Integer_Vectors; with Standard_Integer_Vectors_io; with Standard_Integer_Matrices; with Standard_Integer_Matrices_io; with Standard_Integer_VecMats; with Standard_Integer_VecMats_io; with Standard_Integer_Linear_Solvers; with Standard_Random_Matrices; use Standard_Random_Matrices; with Multprec_Random_Matrices; use Multprec_Random_Matrices; with Multprec_Integer_Vectors; with Multprec_Integer_Vectors_io; with Multprec_Integer_Matrices; with Multprec_Integer_Matrices_io; with Multprec_Integer_Linear_Solvers; procedure ts_intmat is -- DESCRIPTION : -- Tests the matrix packages of standard and multi-precision integers. procedure Test_Standard_io is use Standard_Integer_Matrices,Standard_Integer_Matrices_io; n,m : natural; begin put("Give the number of rows : "); get(n); put("Give the number of columns : "); get(m); declare mat : Matrix(1..n,1..m); begin put("Give "); put(n,1); put("x"); put(m,1); put_line(" integer matrix : "); get(mat); put_line("Your matrix : "); put(mat); end; end Test_Standard_io; procedure Test_Standard_VecMat_io is use Standard_Integer_Matrices,Standard_Integer_Matrices_io; use Standard_Integer_VecMats,Standard_Integer_VecMats_io; n,n1,n2 : natural; lv : Link_to_VecMat; begin put("Give the number of matrices : "); get(n); put("Give #rows : "); get(n1); put("Give #columns : "); get(n2); put("Give "); put(n,1); put(" "); put(n1,1); put("-by-"); put(n2,1); put_line(" integer matrices : "); get(n,n1,n2,lv); put_line("The vector of matrices :"); put(lv); end Test_Standard_VecMat_io; procedure Random_Test_Standard_Solver ( n,m : in natural; low,upp : in integer ) is use Standard_Integer_Vectors,Standard_Integer_Vectors_io; use Standard_Integer_Matrices; use Standard_Integer_Linear_Solvers; mat : Matrix(1..n,1..m) := Random_Matrix(n,m,low,upp); wrk : Matrix(1..n,1..m) := mat; sol : Vector(1..m); res : Vector(1..n); begin Upper_Triangulate(wrk); Solve0(wrk,sol); res := mat*sol; put("The residual : "); put(res); put(" of solution : "); put(sol); new_line; end Random_Test_Standard_Solver; procedure Random_Test_Multprec_Solver ( n,m,sz : in natural ) is use Multprec_Integer_Vectors,Multprec_Integer_Vectors_io; use Multprec_Integer_Matrices,Multprec_Integer_Matrices_io; use Multprec_Integer_Linear_Solvers; mat : Matrix(1..n,1..m) := Random_Matrix(n,m,sz); wrk : Matrix(1..n,1..m); sol : Vector(1..m); res : Vector(1..n); begin Copy(mat,wrk); Upper_Triangulate(wrk); Solve0(wrk,sol); res := mat*sol; put("The residual : "); put(res); put(" of solution : "); put(sol); new_line; end Random_Test_Multprec_Solver; procedure Random_Test_Standard_Solvers is n,m,nb : natural; low,upp : integer; begin put("Give number of tests : "); get(nb); put("Give number of rows : "); get(n); put("Give number of columns : "); get(m); put("Give lower bound for numbers : "); get(low); put("Give upper bound for numbers : "); get(upp); for i in 1..nb loop Random_Test_Standard_Solver(n,m,low,upp); end loop; end Random_Test_Standard_Solvers; procedure Random_Test_Multprec_Solvers is n,m,nb,sz : natural; begin put("Give number of tests : "); get(nb); put("Give number of rows : "); get(n); put("Give number of columns : "); get(m); put("Give the size of the numbers : "); get(sz); for i in 1..nb loop Random_Test_Multprec_Solver(n,m,sz); end loop; end Random_Test_Multprec_Solvers; procedure Interactive_Test_Standard_Solvers is use Standard_Integer_Vectors,Standard_Integer_Vectors_io; use Standard_Integer_Matrices,Standard_Integer_Matrices_io; use Standard_Integer_Linear_Solvers; n,m : natural; begin put("Give the number of rows : "); get(n); put("Give the number of columns : "); get(m); declare sol : Vector(1..m) := (1..m => 0); res : Vector(1..n); mat,wrk : Matrix(1..n,1..m); l : Matrix(1..n,1..n); begin put("Give "); put(n,1); put("x"); put(m,1); put_line(" integer matrix : "); get(mat); put_line("Your matrix : "); put(mat); wrk := mat; Upper_Triangulate(l,wrk); put_line("The matrix in upper triangular form : "); put(wrk); put_line("The transformation matrix T : "); put(l); put_line("product of T and original matrix : "); put(l*mat); Solve0(wrk,sol); put_line("The solution of the homogeneous system : "); put(sol); new_line; res := mat*sol; put("The residual : "); put(res); new_line; end; end Interactive_Test_Standard_Solvers; procedure Test_Multprec_io is use Multprec_Integer_Matrices,Multprec_Integer_Matrices_io; n,m : natural; begin put("Give the number of rows : "); get(n); put("Give the number of columns : "); get(m); declare mat : Matrix(1..n,1..m); begin put("Give "); put(n,1); put("x"); put(m,1); put_line(" integer matrix : "); get(mat); put_line("Your matrix : "); put(mat); new_line; end; end Test_Multprec_io; procedure Interactive_Test_Multprec_Solvers is use Multprec_Integer_Vectors,Multprec_Integer_Vectors_io; use Multprec_Integer_Matrices,Multprec_Integer_Matrices_io; use Multprec_Integer_Linear_Solvers; n,m : natural; begin put("Give the number of rows : "); get(n); put("Give the number of columns : "); get(m); declare sol : Vector(1..m); res : Vector(1..n); mat,wrk : Matrix(1..n,1..m); l : Matrix(1..n,1..n); begin put("Give "); put(n,1); put("x"); put(m,1); put_line(" integer matrix : "); get(mat); put_line("Your matrix : "); put(mat); Copy(mat,wrk); Upper_Triangulate(l,wrk); put_line("The matrix in upper triangular form : "); put(wrk); put_line("The transformation matrix T : "); put(l); put_line("product of T and original matrix : "); put(l*mat); Solve0(wrk,sol); put_line("The solution of the homogeneous system : "); put(sol); new_line; res := mat*sol; put("The residual : "); put(res); new_line; end; end Interactive_Test_Multprec_Solvers; procedure Test_Multprec_Matrix_Vector_Product is use Multprec_Integer_Vectors,Multprec_Integer_Vectors_io; use Multprec_Integer_Matrices,Multprec_Integer_Matrices_io; n,m : natural; begin put("Give the number of rows : "); get(n); put("Give the number of columns : "); get(m); declare mat : Matrix(1..n,1..m); vec : Vector(1..m); prod : Vector(1..n); begin put("Give "); put(n,1); put("x"); put(m,1); put_line(" integer matrix : "); get(mat); put_line("Your matrix : "); put(mat); put("Give an " ); put(m,1); put("-vector : "); get(vec); put("Your vector : "); put(vec); new_line; prod := mat*vec; put_line("The matrix-vector product : "); put(prod); new_line; end; end Test_Multprec_Matrix_Vector_Product; procedure Main is ans : character; begin new_line; put_line("Interactive testing of matrices of integer numbers"); new_line; loop put_line("Choose one of the following : "); put_line(" 0. exit this program."); put_line(" 1. io of matrices of standard numbers."); put_line(" 2. io of vectors of matrices of standard numbers."); put_line(" 3. solve given linear systems of standard numbers."); put_line(" 4. solve random linear systems of standard numbers."); put_line(" 5. io of matrices of multi-precision numbers."); put_line(" 6. solve given linear systems of multi-precision numbers."); put_line(" 7. solve random linear systems of multi-precision numbers."); put_line(" 8. test multi-precision matrix-vector product."); put("Make your choice (0,1,2,3,4,5,6,7 or 8) : "); get(ans); exit when (ans = '0'); case ans is when '1' => Test_Standard_io; when '2' => Test_Standard_VecMat_io; when '3' => Interactive_Test_Standard_Solvers; when '4' => Random_Test_Standard_Solvers; when '5' => Test_Multprec_io; when '6' => Interactive_Test_Multprec_Solvers; when '7' => Random_Test_Multprec_Solvers; when '8' => Test_Multprec_Matrix_Vector_Product; when others => null; end case; end loop; end Main; begin Main; end ts_intmat;