X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=check%2Fexam_matrices.cpp;h=2e14f49482fbbfa836a052f61b038a626ff4e19a;hp=9a88c8c2bc80af55f7f3197ade0828280d8f465f;hb=581244b7b8fc9b5f81291e1a3f5731939e3f3d8e;hpb=68fdf425abf14d016d5f95ee7b9d06a19a3c5926 diff --git a/check/exam_matrices.cpp b/check/exam_matrices.cpp index 9a88c8c2..2e14f494 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-2003 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2008 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,11 +17,14 @@ * * 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 -#include "exams.h" +#include +#include "ginac.h" +using namespace std; +using namespace GiNaC; static unsigned matrix_determinants() { @@ -241,6 +244,46 @@ static unsigned matrix_evalm() 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; @@ -297,7 +340,6 @@ 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; @@ -305,14 +347,13 @@ unsigned exam_matrices() 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(); +}