1 /** @file time_vandermonde.cpp
3 * Calculates determinants of dense symbolic Vandermonde materices with
4 * monomials in one single variable as entries.
5 * For 4x4 our matrix would look like this:
6 * [[1,a,a^2,a^3], [1,-a,a^2,-a^3], [1,a^2,a^4,a^6], [1,-a^2,a^4,-a^6]]
10 * GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 static unsigned vandermonde_det(unsigned size)
34 // construct Vandermonde matrix:
36 for (unsigned ro=0; ro<size; ++ro)
37 for (unsigned co=0; co<size; ++co)
39 M.set(ro,co,pow(-pow(a,1+ro/2),co));
41 M.set(ro,co,pow(pow(a,1+ro/2),co));
43 // compute determinant:
44 ex vdet = M.determinant();
46 // dirty consistency check of result:
47 if (!vdet.subs(a==1).is_zero()) {
48 clog << "Determaint of Vandermonde matrix " << endl
50 << "was miscalculated: det(M)==" << vdet << endl;
57 unsigned time_vandermonde(void)
61 cout << "timing determinant of univariate symbolic Vandermonde matrices" << flush;
62 clog << "-------determinant of univariate symbolic Vandermonde matrices:" << endl;
64 vector<unsigned> sizes;
73 for (vector<unsigned>::iterator i=sizes.begin(); i!=sizes.end(); ++i) {
76 result += vandermonde_det(*i);
77 // correct for very small times:
78 while (swatch.read()<0.02) {
82 times.push_back(swatch.read()/count);
88 clog << "(no output)" << endl;
93 cout << endl << " dim: ";
94 for (vector<unsigned>::iterator i=sizes.begin(); i!=sizes.end(); ++i)
95 cout << '\t' << *i << 'x' << *i;
96 cout << endl << " time/s:";
97 for (vector<double>::iterator i=times.begin(); i!=times.end(); ++i)
98 cout << '\t' << int(1000*(*i))*0.001;