Polymetic  1.1
A c++ library for polynomial and matrix arithmetic, focused on applications in Kinematics.
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
Test_MatrixAlgorithms_double.cpp
Go to the documentation of this file.
1 // Copyright 2018 Dhruvesh Nikhilkumar Patel
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
18 #include "../include/Matrix.ipp"
19 #include "../include/MatrixAlgorithms.ipp"
20 #include "gtest/gtest.h"
21 namespace{
22  class MatrixTest : public ::testing::Test{
23  public:
24 
25  using entryT = double;
28 
29  }
30  virtual ~MatrixTest(){
31 
32  }
33 
34  protected:
35  //virtual void SetUp() {
36 
37  //}
38 
39  //virtual void TearDown() {
40 
41  //}
42 
43 
44  };
45 
46 
47 
48 
49  TEST_F(MatrixTest,trace_with_power){
50 
51  Matrix<entryT> mi (3,3);
52  mi(0,0)=1;
53  mi(0,1)=0;
54  mi(0,2)=0;
55  mi(1,0)=0;
56  mi(1,1)=1;
57  mi(1,2)=0;
58  mi(2,0)=0;
59  mi(2,1)=0;
60  mi(2,2)=1;
61 
62  entryT tri = trace(mi,5);
63  ASSERT_DOUBLE_EQ(tri,3);
64 
65  Matrix<entryT> m2 (3,3);
66  m2(0,0)=1;
67  m2(0,1)=2;
68  m2(0,2)=3;
69  m2(1,0)=4;
70  m2(1,1)=5;
71  m2(1,2)=6;
72  m2(2,0)=7;
73  m2(2,1)=8;
74  m2(2,2)=9;
75 
76  entryT tr2 = trace(m2,3);
77  ASSERT_DOUBLE_EQ(tr2,4185);
78 
79  Matrix<entryT> m (3,3);
80  m(0,0)=345.5;
81  m(0,1)=55;
82  m(0,2)=3;
83  m(1,0)=2.3;
84  m(1,1)=100.4;
85  m(1,2)=3.7;
86  m(2,0)=0.02;
87  m(2,1)=30;
88  m(2,2)=456;
89 
90 
91  entryT tr = trace(m,3);
92  ASSERT_DOUBLE_EQ(tr,1.37428563169e+8);
93 
94 
95 
96  }
97  TEST_F(MatrixTest,determinant){
98 
99  Matrix<entryT> mi (3,3);
100  mi(0,0)=1;
101  mi(0,1)=0;
102  mi(0,2)=0;
103  mi(1,0)=0;
104  mi(1,1)=1;
105  mi(1,2)=0;
106  mi(2,0)=0;
107  mi(2,1)=0;
108  mi(2,2)=1;
109 
110  entryT di = det(mi);
111  ASSERT_DOUBLE_EQ(di,1);
112 
113  Matrix<entryT> m2 (3,3);
114  m2(0,0)=1;
115  m2(0,1)=2;
116  m2(0,2)=3;
117  m2(1,0)=4;
118  m2(1,1)=5;
119  m2(1,2)=6;
120  m2(2,0)=7;
121  m2(2,1)=8;
122  m2(2,2)=9;
123 
124  entryT d2 = det(m2);
125  ASSERT_DOUBLE_EQ(d2,0);
126 
127  Matrix<entryT> m (3,3);
128  m(0,0)=345.5;
129  m(0,1)=55;
130  m(0,2)=3;
131  m(1,0)=2.3;
132  m(1,1)=100.4;
133  m(1,2)=3.7;
134  m(2,0)=0.02;
135  m(2,1)=30;
136  m(2,2)=456;
137 
138 
139  entryT d = det(m);
140  ASSERT_DOUBLE_EQ(d,1.572198974600e+7);
141 
142 
143 
144  }
145  }
146 int main(int argc,char **argv){
147  ::testing::InitGoogleTest(&argc,argv);
148  return RUN_ALL_TESTS();
149 }
boost::numeric::ublas::matrix< EntryT > Matrix
Typedef for the main matrix class.
Definition: Matrix.hpp:24
MatrixT::value_type det(const MatrixT &M)
Finds the determinant of a square matrix.
int main(int argc, char **argv)
EntryT trace(const Matrix< EntryT > &M)
Finds trace of a square matrix.
Definition: Matrix_impl.ipp:25