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 /* zsolve.c - finds the complex roots of = 0 */
25 #include <gsl/gsl_math.h>
26 #include <gsl/gsl_errno.h>
27 #include <gsl/gsl_complex.h>
28 #include <gsl/gsl_poly.h>
30 /* C-style matrix elements */
31 #define MAT(m,i,j,n) ((m)[(i)*(n) + (j)])
33 /* Fortran-style matrix elements */
34 #define FMAT(m,i,j,n) ((m)[((i)-1)*(n) + ((j)-1)])
36 #include "companion.c"
41 gsl_poly_complex_solve (const double *a, size_t n,
42 gsl_poly_complex_workspace * w,
43 gsl_complex_packed_ptr z)
50 GSL_ERROR ("number of terms must be a positive integer", GSL_EINVAL);
55 GSL_ERROR ("cannot solve for only one term", GSL_EINVAL);
60 GSL_ERROR ("leading term of polynomial must be non-zero", GSL_EINVAL) ;
65 GSL_ERROR ("size of workspace does not match polynomial", GSL_EINVAL);
70 set_companion_matrix (a, n - 1, m);
72 balance_companion_matrix (m, n - 1);
74 status = qr_companion (m, n - 1, z);
78 GSL_ERROR("root solving qr method failed to converge", GSL_EFAILED);