GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
aepbalance.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1994-2018 John W. Eaton
4 Copyright (C) 2008-2018 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
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License 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 <https://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if ! defined (octave_aepbalance_h)
25 #define octave_aepbalance_h 1
26 
27 #include "octave-config.h"
28 
29 #include <algorithm>
30 
31 namespace octave
32 {
33  namespace math
34  {
35  template <typename MT>
36  class aepbalance
37  {
38  public:
39 
40  typedef typename MT::real_column_vector_type VT;
41 
42  aepbalance (void) : balanced_mat (), scale (), ilo (), ihi (), job () { }
43 
44  aepbalance (const MT& a, bool noperm = false, bool noscal = false);
45 
48  ilo(a.ilo), ihi(a.ihi), job(a.job)
49  { }
50 
52  {
53  if (this != &a)
54  {
55  balanced_mat = a.balanced_mat;
56  scale = a.scale;
57  ilo = a.ilo;
58  ihi = a.ihi;
59  job = a.job;
60  }
61 
62  return *this;
63  }
64 
65  virtual ~aepbalance (void) = default;
66 
67  MT balancing_matrix (void) const;
68 
69  MT balanced_matrix (void) const
70  {
71  return balanced_mat;
72  }
73 
74  VT permuting_vector (void) const
75  {
76  octave_idx_type n = balanced_mat.rows ();
77 
78  VT pv (n);
79 
80  for (octave_idx_type i = 0; i < n; i++)
81  pv(i) = i+1;
82 
83  for (octave_idx_type i = n-1; i >= ihi; i--)
84  {
85  octave_idx_type j = scale(i) - 1;
86  std::swap (pv(i), pv(j));
87  }
88 
89  for (octave_idx_type i = 0; i < ilo-1; i++)
90  {
91  octave_idx_type j = scale(i) - 1;
92  std::swap (pv(i), pv(j));
93  }
94 
95  return pv;
96  }
97 
98  VT scaling_vector (void) const
99  {
100  octave_idx_type n = balanced_mat.rows ();
101 
102  VT scv (n);
103 
104  for (octave_idx_type i = 0; i < ilo-1; i++)
105  scv(i) = 1;
106 
107  for (octave_idx_type i = ilo-1; i < ihi; i++)
108  scv(i) = scale(i);
109 
110  for (octave_idx_type i = ihi; i < n; i++)
111  scv(i) = 1;
112 
113  return scv;
114  }
115 
116  protected:
117 
122  char job;
123  };
124  }
125 }
126 
127 #endif
MT::real_column_vector_type VT
Definition: aepbalance.h:40
VT permuting_vector(void) const
Definition: aepbalance.h:74
octave_idx_type ilo
Definition: aepbalance.h:120
VT scaling_vector(void) const
Definition: aepbalance.h:98
aepbalance(const aepbalance &a)
Definition: aepbalance.h:46
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
Definition: cellfun.cc:400
bool swap
Definition: load-save.cc:738
MT balanced_matrix(void) const
Definition: aepbalance.h:69
octave_idx_type ihi
Definition: aepbalance.h:121
aepbalance & operator=(const aepbalance &a)
Definition: aepbalance.h:51
MT balancing_matrix(void) const
for i
Definition: data.cc:5264
virtual ~aepbalance(void)=default