Points&Forces (core)
Software tools facilitating the task of surveying architecture
a_mat_sq.cxx
Go to the documentation of this file.
1 /*
2  Copyright 2010-17 Pierre SMARS (smars@yuntech.edu.tw)
3  This program is free software: you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation, either version 2 of the License, or
6  (at your option) any later version.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 #include "a_mat_sq.h"
17 // .PORTABILITY : ansi C++
18 
19 //***************************************************************************
20 //member functions
21 //-a_mat_sq-----------------------------------------------------------------
23 {
24  //a_mat::~a_mat();
25 }
26 //-compatible----------------------------------------------------------------
27 void a_mat_sq::compatible(const a_mat& m) const
28 {
29  if (m.maxi() != m.maxj()) throw compatibility_error();
30  if (m.maxi() != maxi_) throw compatibility_error();
31 }
32 //-operator=-----------------------------------------------------------------
34 {
35  maxi_ = m.maxi();
36  maxj_ = maxi_;
37  (*x_) = m.x();
38  return (*this);
39 }
40 //---------------------------------------------------------------------------
42 {
43  a_mat_sq m(this->dim());
44  for (UI i = 0; i < maxi_; i++)
45  m(i,i) = 1.;
46  (*this) = m;
47 }
48 //-operator=-----------------------------------------------------------------
50 {
51  this->compatible(m);
52  (*x_) = m.x();
53  return (*this);
54 }
55 //-operator*=----------------------------------------------------------------
57 {
58  this->compatible(m);
59  a_mat r(maxi_,maxj_);
60  double v;
61  for (UI i = 0; i < maxi_; i++)
62  {
63  for (UI j = 0; j < maxi_; j++)
64  {
65  v = 0;
66  for (UI k = 0; k < maxi_; k++)
67  v += (*this)(i,k)*m(k,j);
68  r(i,j) = v;
69  }
70  }
71  (*x_) = r.x();
72  return (*this);
73 }
74 //-trace----------------------------------------------------------------------
75 double a_mat_sq::trace() const
76 {
77  double v;
78  for (int i = 0; i<maxi_; i++)
79  v += (*this)(i,i);
80  return v;
81 }
82 //-determinant----------------------------------------------------------------
83 double a_mat_sq::determinant() const
84 {
85  if (maxi_==1)
86  return (*this)(0,0);
87  else if (maxi_==2)
88  return (*this)(0,0)*(*this)(1,1)-(*this)(1,0)*(*this)(0,1);
89  else if (maxi_==3)
90  {
91  double t1 = (*this)(0,0)*(*this)(1,1)*(*this)(2,2);
92  double t2 = (*this)(0,1)*(*this)(1,2)*(*this)(2,0);
93  double t3 = (*this)(0,2)*(*this)(1,0)*(*this)(2,1);
94  double t4 = (*this)(0,0)*(*this)(1,2)*(*this)(2,1);
95  double t5 = (*this)(0,1)*(*this)(1,0)*(*this)(2,2);
96  double t6 = (*this)(0,2)*(*this)(1,1)*(*this)(2,0);
97  return t1+t2+t3-t4-t5-t6;
98  }
99  else
100  {
101  a_mat_sq M(maxi_-1);
102  double d = 0.;
103  for (int i = 0; i<maxi_; i++)
104  {
105  M = this->sub_matrix(0,i);
106  d += (*this)(0,i)*M.determinant()*(1.-(i%2)*2.);
107  }
108  return d;
109  }
110 }
unsigned int UI
Definition: a_mat.h:23
a square matrix unit
Definition: a_mat_sq.h:29
double determinant() const
Definition: a_mat_sq.cxx:83
UI dim() const
Definition: a_mat_sq.h:36
void settoI()
Definition: a_mat_sq.cxx:41
~a_mat_sq()
Definition: a_mat_sq.cxx:22
a_mat_sq & operator=(const a_mat_sq &m)
Definition: a_mat_sq.cxx:33
double trace() const
Definition: a_mat_sq.cxx:75
void compatible(const a_mat &m) const
Definition: a_mat_sq.cxx:27
a_mat & operator*=(double v)
Definition: a_mat_sq.h:42
Definition: a_mat.h:42
UI maxj_
Definition: a_mat.h:89
std::valarray< double > & x() const
Definition: a_mat.h:53
a_mat sub_matrix(const UI i, const UI j) const
Definition: a_mat.cxx:162
UI maxi_
Definition: a_mat.h:88
UI maxi() const
Definition: a_mat.h:49
UI maxj() const
Definition: a_mat.h:50