GNU Octave  4.0.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
dbleAEPBAL.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1994-2015 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 "dbleAEPBAL.h"
31 #include "f77-fcn.h"
32 
33 extern "C"
34 {
35  F77_RET_T
36  F77_FUNC (dgebal, DGEBAL) (F77_CONST_CHAR_ARG_DECL,
37  const octave_idx_type&, double*,
38  const octave_idx_type&, octave_idx_type&,
39  octave_idx_type&, double*, octave_idx_type&
41 
42  F77_RET_T
43  F77_FUNC (dgebak, DGEBAK) (F77_CONST_CHAR_ARG_DECL,
45  const octave_idx_type&, const octave_idx_type&,
46  const octave_idx_type&, const double*,
47  const octave_idx_type&, double*,
48  const octave_idx_type&, octave_idx_type&
51 }
52 
53 AEPBALANCE::AEPBALANCE (const Matrix& a, bool noperm, bool noscal)
55 {
56  octave_idx_type n = a.cols ();
57 
58  if (a.rows () != n)
59  {
60  (*current_liboctave_error_handler) ("AEPBALANCE requires square matrix");
61  return;
62  }
63 
64  octave_idx_type info;
65 
66  scale = ColumnVector (n);
67  double *pscale = scale.fortran_vec ();
68 
69  balanced_mat = a;
70  double *p_balanced_mat = balanced_mat.fortran_vec ();
71 
72  job = noperm ? (noscal ? 'N' : 'S') : (noscal ? 'P' : 'B');
73 
74  F77_XFCN (dgebal, DGEBAL, (F77_CONST_CHAR_ARG2 (&job, 1),
75  n, p_balanced_mat, n, ilo, ihi, pscale, info
76  F77_CHAR_ARG_LEN (1)));
77 }
78 
79 Matrix
81 {
83  Matrix balancing_mat (n, n, 0.0);
84  for (octave_idx_type i = 0; i < n; i++)
85  balancing_mat.elem (i ,i) = 1.0;
86 
87  double *p_balancing_mat = balancing_mat.fortran_vec ();
88  const double *pscale = scale.fortran_vec ();
89 
90  octave_idx_type info;
91 
92  char side = 'R';
93 
94  F77_XFCN (dgebak, DGEBAK, (F77_CONST_CHAR_ARG2 (&job, 1),
95  F77_CONST_CHAR_ARG2 (&side, 1),
96  n, ilo, ihi, pscale, n,
97  p_balancing_mat, n, info
99  F77_CHAR_ARG_LEN (1)));
100 
101  return balancing_mat;
102 }
F77_RET_T F77_CONST_CHAR_ARG_DECL
Definition: dbleAEPBAL.cc:44
#define F77_CHAR_ARG_LEN(l)
Definition: f77-fcn.h:253
T & elem(octave_idx_type n)
Definition: Array.h:380
#define F77_XFCN(f, F, args)
Definition: f77-fcn.h:51
AEPBALANCE(void)
Definition: dbleAEPBAL.h:40
octave_idx_type rows(void) const
Definition: Array.h:313
#define F77_CONST_CHAR_ARG2(x, l)
Definition: f77-fcn.h:251
Matrix balancing_matrix(void) const
Definition: dbleAEPBAL.cc:80
#define F77_RET_T
Definition: f77-fcn.h:264
Definition: dMatrix.h:35
ColumnVector(void)
Definition: dColVector.h:37
F77_RET_T const octave_idx_type double const octave_idx_type octave_idx_type octave_idx_type double octave_idx_type & F77_CHAR_ARG_LEN_DECL
Definition: dbleAEPBAL.cc:37
F77_RET_T F77_FUNC(dgebal, DGEBAL)(F77_CONST_CHAR_ARG_DECL
const T * fortran_vec(void) const
Definition: Array.h:481
octave_idx_type cols(void) const
Definition: Array.h:321