Debian Codegraph @

examples/charpoly.C

raw
1 /* Copyright (c) FFLAS-FFPACK
2 * ========LICENCE========
3 * This file is part of the library FFLAS-FFPACK.
4 *
5 * FFLAS-FFPACK is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 * ========LICENCE========
19 */
20
21 #include <iostream>
22
23 #include "fflas-ffpack/fflas-ffpack.h"
24
25 /**
26 * This example computes the characteristic polynomial of a matrix
27 * over a defined finite field.
28 *
29 * Outputs the characteristic polynomial.
30 */
31 int main(int argc, char** argv)
32 {
33 if (argc != 3) {
34 std::cerr << "Usage: charpoly <p> <matrix>" << std::endl;
35 return -1;
36 }
37
38 int p = atoi(argv[1]);
39 std::string file = argv[2];
40
41 // Creating the finite field Z/pZ (assuming p>2, use Modular<float> for p=2)
42 typedef Givaro::ModularBalanced<double> F_t;
43
44 // Creating polynomial ring
45 typedef Givaro::Poly1Dom<F_t> PolyRing_t;
46 typedef PolyRing_t::Element Poly_t;
47
48 // Reading the matrix from a file
49 F_t F(p);
50 double* A;
51 size_t m, n;
52 FFLAS::ReadMatrix(file.c_str(), F, m, n, A);
53
54 if (n != m) {
55 std::cerr << "Input should be a square matrix" << std::endl;
56 return -1;
57 }
58
59 Poly_t charp(n+1);
60 PolyRing_t PolyRing(F, 'X');
61 FFPACK::CharPoly(PolyRing, charp, n, A, n);
62 PolyRing.write(std::cout, charp) << std::endl;
63
64 FFLAS::fflas_delete(A);
65
66 return 0;
67 }
68 /* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
69 // vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s