GNU Octave  6.2.0
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-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_aepbalance_h)
27 #define octave_aepbalance_h 1
28 
29 #include "octave-config.h"
30 
31 #include <algorithm>
32 
33 namespace octave
34 {
35  namespace math
36  {
37  template <typename MT>
38  class aepbalance
39  {
40  public:
41 
42  typedef typename MT::real_column_vector_type VT;
43 
44  aepbalance (void) : balanced_mat (), scale (), ilo (), ihi (), job () { }
45 
46  aepbalance (const MT& a, bool noperm = false, bool noscal = false);
47 
50  ilo(a.ilo), ihi(a.ihi), job(a.job)
51  { }
52 
54  {
55  if (this != &a)
56  {
58  scale = a.scale;
59  ilo = a.ilo;
60  ihi = a.ihi;
61  job = a.job;
62  }
63 
64  return *this;
65  }
66 
67  virtual ~aepbalance (void) = default;
68 
69  MT balancing_matrix (void) const;
70 
71  MT balanced_matrix (void) const
72  {
73  return balanced_mat;
74  }
75 
76  VT permuting_vector (void) const
77  {
78  octave_idx_type n = balanced_mat.rows ();
79 
80  VT pv (n);
81 
82  for (octave_idx_type i = 0; i < n; i++)
83  pv(i) = i+1;
84 
85  for (octave_idx_type i = n-1; i >= ihi; i--)
86  {
87  octave_idx_type j = scale(i) - 1;
88  std::swap (pv(i), pv(j));
89  }
90 
91  for (octave_idx_type i = 0; i < ilo-1; i++)
92  {
93  octave_idx_type j = scale(i) - 1;
94  std::swap (pv(i), pv(j));
95  }
96 
97  return pv;
98  }
99 
100  VT scaling_vector (void) const
101  {
102  octave_idx_type n = balanced_mat.rows ();
103 
104  VT scv (n);
105 
106  for (octave_idx_type i = 0; i < ilo-1; i++)
107  scv(i) = 1;
108 
109  for (octave_idx_type i = ilo-1; i < ihi; i++)
110  scv(i) = scale(i);
111 
112  for (octave_idx_type i = ihi; i < n; i++)
113  scv(i) = 1;
114 
115  return scv;
116  }
117 
118  protected:
119 
124  char job;
125  };
126  }
127 }
128 
129 #endif
aepbalance(const aepbalance &a)
Definition: aepbalance.h:48
octave_idx_type ilo
Definition: aepbalance.h:122
aepbalance(const MT &a, bool noperm=false, bool noscal=false)
VT permuting_vector(void) const
Definition: aepbalance.h:76
octave_idx_type ihi
Definition: aepbalance.h:123
aepbalance & operator=(const aepbalance &a)
Definition: aepbalance.h:53
MT balancing_matrix(void) const
VT scaling_vector(void) const
Definition: aepbalance.h:100
MT balanced_matrix(void) const
Definition: aepbalance.h:71
MT::real_column_vector_type VT
Definition: aepbalance.h:42
virtual ~aepbalance(void)=default
octave_idx_type n
Definition: mx-inlines.cc:753