MatrixBaseOperators.hpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
43 #ifndef GNSSTK_MATRIX_BASE_OPERATORS_HPP
44 #define GNSSTK_MATRIX_BASE_OPERATORS_HPP
45 
46 #include <fstream> // for copyfmt
47 #include <iomanip>
48 #include "MatrixBase.hpp"
49 
50 namespace gnsstk
51 {
52 
54 
55 
57  template <class T, class E>
58  std::ostream& operator<<(std::ostream& s, const ConstMatrixBase<T, E>& a)
59  {
60  size_t i, j;
61  std::ofstream savefmt;
62  savefmt.copyfmt(s);
63  for (i=0; i<a.rows(); i++)
64  {
65  for (j=0; j< a.cols(); j++) {
66  s << std::setw(1) << ' ';
67  s.copyfmt(savefmt);
68  s << a(i,j);
69  }
70  if(i < a.rows()-1) s << std::endl;
71  }
72  return s;
73  }
74 
79  template <class T, class BaseClass>
81  {
82  BaseClass& me = static_cast<BaseClass&>(m);
83  if ( (me.rows() != me.cols()) || (me.cols() < 1) )
84  {
85  MatrixException e("invalid matrix dimensions for ident()");
86  GNSSTK_THROW(e);
87  }
88  m.assignFrom(T(0));
89  size_t i;
90  for (i = 0; i < me.rows(); i++)
91  me(i,i) = T(1);
92  return me;
93  }
94 
99  template <class T, class BaseClass>
101  {
102  if ((!m.isSquare()) || (m.rows() == 0))
103  {
104  MatrixException e("Invalid matrix for trace()");
105  GNSSTK_THROW(e);
106  }
107  size_t index = 0;
108  T answer = m(index,index);
109  for (index = 1; index < m.rows(); index++)
110  answer += m(index,index);
111  return answer;
112  }
113 
117  template <class T, class BaseClass>
119  {
120  T sum(0);
121  size_t i,j;
122  for (i = 0; i < m.rows(); i++)
123  for (j = 0; j < m.cols(); j++)
124  sum += m(i,j) * m(i,j);
125  return SQRT(sum);
126  }
127 
131  template <class T, class BaseClass>
133  {
134  T sum(0), tempSum;
135  size_t i,j;
136  for (i = 0; i < m.rows(); i++)
137  {
138  tempSum = T(0);
139  for (j = 0; j < m.cols(); j++)
140  tempSum += ABS(m(i,j));
141  if (tempSum > sum)
142  sum = tempSum;
143  }
144  return sum;
145  }
146 
152  template <class T, class BaseClass>
154  {
155  if (!l.isSquare() || (l.rows() <= 1))
156  {
157  MatrixException e("Invalid matrix for det()");
158  GNSSTK_THROW(e);
159  }
160  // go recursion!
161  if (l.rows() == 2)
162  return l(0,0)*l(1,1) - l(0,1)*l(1,0);
163  else
164  {
165  // use v[0,0] * det(minor matrix(0,0)) +
166  // v[0,1] * det(minor matrix(0,1)) + ...
167  size_t i;
168  int sign;
169  T det = 0;
170  for (i = 0; i < l.rows(); i++)
171  {
172  sign = (i % 2) ? -1 : 1;
173  if (l(0,i) != 0)
174  det += sign * l(0,i) * slowDet(minorMatrix(l,0,i));
175  }
176  return det;
177  }
178  }
179 
181 
182 } // namespace
183 
184 #endif
gnsstk::RefMatrixBase
Definition: MatrixBase.hpp:217
gnsstk::ident
BaseClass & ident(RefMatrixBase< T, BaseClass > &m)
Definition: MatrixBaseOperators.hpp:80
gnsstk::normF
T normF(const ConstMatrixBase< T, BaseClass > &m)
Definition: MatrixBaseOperators.hpp:118
SQRT
#define SQRT(x)
Definition: MathBase.hpp:74
gnsstk::sum
T sum(const ConstVectorBase< T, BaseClass > &l)
Definition: VectorBaseOperators.hpp:84
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::det
T det(const ConstMatrixBase< T, BaseClass > &m)
Definition: MatrixOperators.hpp:345
gnsstk::minorMatrix
Matrix< T > minorMatrix(const ConstMatrixBase< T, BaseClass > &l, size_t row, size_t col)
Definition: MatrixOperators.hpp:266
gnsstk::ConstMatrixBase::rows
size_t rows() const
the number of rows in the matrix
Definition: MatrixBase.hpp:81
gnsstk::ConstMatrixBase::cols
size_t cols() const
the number of columns in the matrix
Definition: MatrixBase.hpp:78
gnsstk::operator<<
std::ostream & operator<<(std::ostream &s, const ObsEpoch &oe) noexcept
Definition: ObsEpochMap.cpp:54
MatrixBase.hpp
gnsstk::trace
T trace(const ConstMatrixBase< T, BaseClass > &m)
Definition: MatrixBaseOperators.hpp:100
ABS
#define ABS(x)
Definition: MathBase.hpp:73
gnsstk::ConstMatrixBase
Definition: MatrixBase.hpp:65
GNSSTK_THROW
#define GNSSTK_THROW(exc)
Definition: Exception.hpp:366
gnsstk::RefMatrixBase::assignFrom
BaseClass & assignFrom(const ConstMatrixBase< T, E > &x)
Definition: MatrixBase.hpp:288
gnsstk::normCol
T normCol(const ConstMatrixBase< T, BaseClass > &m)
Definition: MatrixBaseOperators.hpp:132
gnsstk::ConstMatrixBase::isSquare
bool isSquare() const
returns true if this is a square matrix (false for a null matrix).
Definition: MatrixBase.hpp:89
gnsstk::slowDet
T slowDet(const ConstMatrixBase< T, BaseClass > &l)
Definition: MatrixBaseOperators.hpp:153


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:39