X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=check%2Fexam_matrices.cpp;h=ed01568d13d326ec8eb899f057ca2954d49a8a91;hp=5c98b1dc07f33f71b0e1607f38db37ddadb261fd;hb=0289100f425e420da988a709cd52616b6d69d348;hpb=ae3044935ddf13dd325f6e11770357b99bbe6095 diff --git a/check/exam_matrices.cpp b/check/exam_matrices.cpp index 5c98b1dc..ed01568d 100644 --- a/check/exam_matrices.cpp +++ b/check/exam_matrices.cpp @@ -3,7 +3,7 @@ * Here we examine manipulations on GiNaC's symbolic matrices. */ /* - * GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2011 Johannes Gutenberg University Mainz, Germany * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,13 +17,17 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "ginac.h" +using namespace GiNaC; + +#include #include -#include "exams.h" +using namespace std; -static unsigned matrix_determinants(void) +static unsigned matrix_determinants() { unsigned result = 0; ex det; @@ -110,7 +114,7 @@ static unsigned matrix_determinants(void) return result; } -static unsigned matrix_invert1(void) +static unsigned matrix_invert1() { unsigned result = 0; matrix m(1,1); @@ -128,7 +132,7 @@ static unsigned matrix_invert1(void) return result; } -static unsigned matrix_invert2(void) +static unsigned matrix_invert2() { unsigned result = 0; matrix m(2,2); @@ -150,7 +154,7 @@ static unsigned matrix_invert2(void) return result; } -static unsigned matrix_invert3(void) +static unsigned matrix_invert3() { unsigned result = 0; matrix m(3,3); @@ -180,7 +184,7 @@ static unsigned matrix_invert3(void) return result; } -static unsigned matrix_solve2(void) +static unsigned matrix_solve2() { // check the solution of the multiple system A*X = B: // [ 1 2 -1 ] [ x0 y0 ] [ 4 0 ] @@ -216,7 +220,72 @@ static unsigned matrix_solve2(void) return result; } -static unsigned matrix_misc(void) +static unsigned matrix_evalm() +{ + unsigned result = 0; + + matrix S(2, 2, lst( + 1, 2, + 3, 4 + )), T(2, 2, lst( + 1, 1, + 2, -1 + )), R(2, 2, lst( + 27, 14, + 36, 26 + )); + + ex e = ((S + T) * (S + 2*T)); + ex f = e.evalm(); + if (!f.is_equal(R)) { + clog << "Evaluating " << e << " erroneously returned " << f << " instead of " << R << endl; + result++; + } + + return result; +} + +static unsigned matrix_rank() +{ + unsigned result = 0; + symbol x("x"), y("y"); + matrix m(3,3); + + // the zero matrix always has rank 0 + if (m.rank() != 0) { + clog << "The rank of " << m << " was not computed correctly." << endl; + ++result; + } + + // a trivial rank one example + m = 1, 0, 0, + 2, 0, 0, + 3, 0, 0; + if (m.rank() != 1) { + clog << "The rank of " << m << " was not computed correctly." << endl; + ++result; + } + + // an example from Maple's help with rank two + m = x, 1, 0, + 0, 0, 1, + x*y, y, 1; + if (m.rank() != 2) { + clog << "The rank of " << m << " was not computed correctly." << endl; + ++result; + } + + // the 3x3 unit matrix has rank 3 + m = ex_to(unit_matrix(3,3)); + if (m.rank() != 3) { + clog << "The rank of " << m << " was not computed correctly." << endl; + ++result; + } + + return result; +} + +static unsigned matrix_misc() { unsigned result = 0; matrix m1(2,2); @@ -267,26 +336,25 @@ static unsigned matrix_misc(void) return result; } -unsigned exam_matrices(void) +unsigned exam_matrices() { unsigned result = 0; cout << "examining symbolic matrix manipulations" << flush; - clog << "----------symbolic matrix manipulations:" << endl; result += matrix_determinants(); cout << '.' << flush; result += matrix_invert1(); cout << '.' << flush; result += matrix_invert2(); cout << '.' << flush; result += matrix_invert3(); cout << '.' << flush; result += matrix_solve2(); cout << '.' << flush; + result += matrix_evalm(); cout << "." << flush; + result += matrix_rank(); cout << "." << flush; result += matrix_misc(); cout << '.' << flush; - if (!result) { - cout << " passed " << endl; - clog << "(no output)" << endl; - } else { - cout << " failed " << endl; - } - return result; } + +int main(int argc, char** argv) +{ + return exam_matrices(); +}