1 /** @file check_lsolve.cpp
3 * These test routines do some simple checks on solving linear systems of
4 * symbolic equations. */
7 * GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 static unsigned lsolve1(int size)
28 // A dense size x size matrix in dense univariate random polynomials
34 // Create two dense linear matrices A and B where all entries are random
35 // univariate polynomials
36 matrix A(size,size), B(size,2), X(size,2);
37 for (int ro=0; ro<size; ++ro) {
38 for (int co=0; co<size; ++co)
39 A.set(ro,co,dense_univariate_poly(a, 5));
40 for (int co=0; co<2; ++co)
41 B.set(ro,co,dense_univariate_poly(a, 5));
43 if (A.determinant().is_zero())
44 clog << "lsolve1: singular system!" << endl;
46 // Solve the system A*X==B:
50 bool errorflag = false;
52 Aux = A.mul(X).sub(B);
53 for (int ro=0; ro<size && !errorflag; ++ro)
54 for (int co=0; co<2; ++co)
55 if (!(Aux(ro,co)).normal().is_zero())
58 clog << "Our solve method claims that A*X==B, with matrices" << endl
59 << "A == " << A << endl
60 << "X == " << X << endl
61 << "B == " << B << endl;
67 static unsigned lsolve2(int size)
69 // A dense size x size matrix in dense bivariate random polynomials
72 symbol a("a"), b("b");
75 // Create two dense linear matrices A and B where all entries are dense random
76 // bivariate polynomials:
77 matrix A(size,size), B(size,2), X(size,2);
78 for (int ro=0; ro<size; ++ro) {
79 for (int co=0; co<size; ++co)
80 A.set(ro,co,dense_bivariate_poly(a,b,2));
81 for (int co=0; co<2; ++co)
82 B.set(ro,co,dense_bivariate_poly(a,b,2));
84 if (A.determinant().is_zero())
85 clog << "lsolve2: singular system!" << endl;
87 // Solve the system A*X==B:
91 bool errorflag = false;
93 Aux = A.mul(X).sub(B);
94 for (int ro=0; ro<size && !errorflag; ++ro)
95 for (int co=0; co<2; ++co)
96 if (!(Aux(ro,co)).normal().is_zero())
99 clog << "Our solve method claims that A*X==B, with matrices" << endl
100 << "A == " << A << endl
101 << "X == " << X << endl
102 << "B == " << B << endl;
108 unsigned check_lsolve(void)
112 cout << "checking linear solve" << flush;
113 clog << "---------linear solve:" << endl;
115 //result += lsolve1(2); cout << '.' << flush;
116 //result += lsolve1(3); cout << '.' << flush;
117 //result += lsolve2(2); cout << '.' << flush;
118 //result += lsolve2(3); cout << '.' << flush;
121 cout << " passed " << endl;
122 clog << "(no output)" << endl;
124 cout << " failed " << endl;