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));
45 // compute determinant:
46 ex vdet = M.determinant();
48 // dirty consistency check of result:
49 if (!vdet.subs(a==1).is_zero()) {
50 clog << "Determaint of Vandermonde matrix " << endl
52 << "was miscalculated: det(M)==" << vdet << endl;
59 unsigned time_vandermonde(void)
63 cout << "timing determinant of univariate symbolic Vandermonde matrices" << flush;
64 clog << "-------determinant of univariate symbolic Vandermonde matrices:" << endl;
66 vector<unsigned> sizes;
75 for (vector<unsigned>::iterator i=sizes.begin(); i!=sizes.end(); ++i) {
78 result += vandermonde_det(*i);
79 // correct for very small times:
80 while (swatch.read()<0.02) {
84 times.push_back(swatch.read()/count);
90 clog << "(no output)" << endl;
95 cout << endl << " dim: ";
96 for (vector<unsigned>::iterator i=sizes.begin(); i!=sizes.end(); ++i)
97 cout << '\t' << *i << 'x' << *i;
98 cout << endl << " time/s:";
99 for (vector<double>::iterator i=times.begin(); i!=times.end(); ++i)
100 cout << '\t' << int(1000*(*i))*0.001;