3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 static void balance_companion_matrix (double *m, size_t n);
23 #define RADIX2 (RADIX*RADIX)
26 balance_companion_matrix (double *m, size_t nc)
28 int not_converged = 1;
40 for (i = 0; i < nc; i++)
42 /* column norm, excluding the diagonal */
46 col_norm = fabs (MAT (m, i + 1, i, nc));
52 for (j = 0; j < nc - 1; j++)
54 col_norm += fabs (MAT (m, j, nc - 1, nc));
58 /* row norm, excluding the diagonal */
62 row_norm = fabs (MAT (m, 0, nc - 1, nc));
66 row_norm = fabs (MAT (m, i, i - 1, nc));
70 row_norm = (fabs (MAT (m, i, i - 1, nc))
71 + fabs (MAT (m, i, nc - 1, nc)));
74 if (col_norm == 0 || row_norm == 0)
81 s = col_norm + row_norm;
97 if ((row_norm + col_norm) < 0.95 * s * f)
105 MAT (m, 0, nc - 1, nc) *= g;
109 MAT (m, i, i - 1, nc) *= g;
110 MAT (m, i, nc - 1, nc) *= g;
115 for (j = 0; j < nc; j++)
117 MAT (m, j, i, nc) *= f;
122 MAT (m, i + 1, i, nc) *= f;