GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CmplxAEPBAL.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1994-2013 John W. Eaton
4 Copyright (C) 2008 Jaroslav Hajek
5 
6 This file is part of Octave.
7 
8 Octave is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, see
20 <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27 
28 #include <string>
29 
30 #include "CmplxAEPBAL.h"
31 #include "dMatrix.h"
32 #include "f77-fcn.h"
33 
34 extern "C"
35 {
36  F77_RET_T
37  F77_FUNC (zgebal, ZGEBAL) (F77_CONST_CHAR_ARG_DECL,
39  const octave_idx_type&, octave_idx_type&,
40  octave_idx_type&, double*, octave_idx_type&
42 
43  F77_RET_T
44  F77_FUNC (zgebak, ZGEBAK) (F77_CONST_CHAR_ARG_DECL,
46  const octave_idx_type&, const octave_idx_type&,
47  const octave_idx_type&, const double*,
48  const octave_idx_type&, Complex*,
49  const octave_idx_type&, octave_idx_type&
52 }
53 
55  bool noperm, bool noscal)
57 {
58  octave_idx_type n = a.cols ();
59 
60  if (a.rows () != n)
61  {
62  (*current_liboctave_error_handler) ("AEPBALANCE requires square matrix");
63  return;
64  }
65 
66  octave_idx_type info;
67 
68  scale = ColumnVector (n);
69  double *pscale = scale.fortran_vec ();
70 
71  balanced_mat = a;
72  Complex *p_balanced_mat = balanced_mat.fortran_vec ();
73 
74  job = noperm ? (noscal ? 'N' : 'S') : (noscal ? 'P' : 'B');
75 
76  F77_XFCN (zgebal, ZGEBAL, (F77_CONST_CHAR_ARG2 (&job, 1),
77  n, p_balanced_mat, n, ilo, ihi,
78  pscale, info
79  F77_CHAR_ARG_LEN (1)));
80 }
81 
84 {
86  ComplexMatrix balancing_mat (n, n, 0.0);
87  for (octave_idx_type i = 0; i < n; i++)
88  balancing_mat.elem (i, i) = 1.0;
89 
90  Complex *p_balancing_mat = balancing_mat.fortran_vec ();
91  const double *pscale = scale.fortran_vec ();
92 
93  octave_idx_type info;
94 
95  char side = 'R';
96 
97  F77_XFCN (zgebak, ZGEBAK, (F77_CONST_CHAR_ARG2 (&job, 1),
98  F77_CONST_CHAR_ARG2 (&side, 1),
99  n, ilo, ihi, pscale, n,
100  p_balancing_mat, n, info
101  F77_CHAR_ARG_LEN (1)
102  F77_CHAR_ARG_LEN (1)));
103 
104  return balancing_mat;
105 }