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
fCmplxAEPBAL.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 "fCmplxAEPBAL.h"
31 #include "fMatrix.h"
32 #include "f77-fcn.h"
33 
34 extern "C"
35 {
36  F77_RET_T
37  F77_FUNC (cgebal, CGEBAL) (F77_CONST_CHAR_ARG_DECL,
39  const octave_idx_type&, octave_idx_type&,
40  octave_idx_type&, float*, octave_idx_type&
42 
43  F77_RET_T
44  F77_FUNC (cgebak, CGEBAK) (F77_CONST_CHAR_ARG_DECL,
46  const octave_idx_type&, const octave_idx_type&,
47  const octave_idx_type&, const float*,
48  const octave_idx_type&, FloatComplex*,
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 
69  float *pscale = scale.fortran_vec ();
70 
71  balanced_mat = a;
72  FloatComplex *p_balanced_mat = balanced_mat.fortran_vec ();
73 
74  job = noperm ? (noscal ? 'N' : 'S') : (noscal ? 'P' : 'B');
75 
76  F77_XFCN (cgebal, CGEBAL, (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  FloatComplexMatrix 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  FloatComplex *p_balancing_mat = balancing_mat.fortran_vec ();
91  const float *pscale = scale.fortran_vec ();
92 
93  octave_idx_type info;
94 
95  char side = 'R';
96 
97  F77_XFCN (cgebak, CGEBAK, (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 }