Larus glider flight sensor system 3.9.2024
Software-In-The-Loop test and validation system
Loading...
Searching...
No Matches
matrix.h
Go to the documentation of this file.
1/***********************************************************************/
25#ifndef MATRIX_H
26#define MATRIX_H
27
28#include "vector.h"
29
30template <class datatype, int size> class vector;
31
33template <class datatype, int size> class matrix
34 {
35public:
37 matrix(void);
40 matrix( const datatype *data);
43 matrix( const datatype data[size][size]);
45 matrix( const matrix & right);
46
48 matrix & operator = ( const matrix & right);
50 vector <datatype, size> operator *( const vector <datatype, size> & right) const;
55
56//#ifdef DEBUG
58 void print(void);
59//#endif
60//protected:
63 };
64
65
66template <class datatype, int size> matrix <datatype, size>::matrix()
67 {
68 for( int i=0; i<size; ++i)
69 for( int k=0; k<size; ++k)
70 e[i][k]=(i==k) ? 1.0 : 0.0;
71 }
72
73template<class datatype, int size>
75 {
76 for (int k = 0; k < size; ++k)
77 for (int i = 0; i < size; ++i)
78 e[k][i] = data[k][i];
79 }
80
81template<class datatype, int size>
83 {
84 if (data == 0) // create unity matrix if no initialization
85 for (int k = 0; k < size; ++k)
86 for (int i = 0; i < size; ++i)
87 e[k][i] = i==k ? 1.0 : 0.0;
88 else
89 for (int k = 0; k < size; ++k)
90 for (int i = 0; i < size; ++i)
91 e[k][i] = *data++;
92 }
93
94// copy constructor
95template <class datatype, int size> matrix <datatype, size>::matrix( const matrix <datatype, size> & right)
96 {
97 for( int k=0; k<size; ++k)
98 for( int i=0; i<size; ++i)
99 e[i][k]=right.e[i][k];
100 }
101
103 {
104 for( int i=0; i<size; ++i)
105 for( int k=0; k<size; ++k)
106 e[i][k]=right.e[i][k];
107 return *this;
108 }
109
110template <class datatype, int size>
111 vector <datatype, size> matrix <datatype, size>::operator *( const vector <datatype, size> & right) const //returns a vector<datatype, size> and
112 { //actual object is matrix<datatype, size>
115 for( int row=0; row<size; ++row)
116 {
117 tmp=0.0;
118 for( int col=0; col<size; ++col)
119 tmp+=e[row][col]*right.e[col];
120 retv.e[row]=tmp;
121 }
122 return retv;
123 }
124
125template <class datatype, int size>
127 { //actual object is matrix<datatype, size>
130 for( int row=0; row<size; ++row)
131 {
132 tmp=0.0;
133 for( int col=0; col<size; ++col)
134 tmp+=e[col][row]*right.e[col];
135 retv.e[row]=tmp;
136 }
137 return retv;
138 }
139
140#endif
mathematical square matrix class
Definition matrix.h:34
matrix(const matrix &right)
copy constructor
Definition matrix.h:95
matrix(void)
default constructor creates unity matrix
Definition matrix.h:66
vector< datatype, size > operator*(const vector< datatype, size > &right) const
multiplication (matrix times vector) -> vector
Definition matrix.h:111
datatype e[size][size]
matrix implementation as 2 dimensional array of datatype
Definition matrix.h:62
matrix< datatype, size > transpose(void)
matrix transposition
vector< datatype, size > reverse_map(const vector< datatype, size > &right) const
multiplication (matrix times vector) -> vector
Definition matrix.h:126
matrix(const datatype data[size][size])
Definition matrix.h:74
matrix(const datatype *data)
Definition matrix.h:82
void print(void)
dump to cout debug helper function
matrix & operator=(const matrix &right)
copy assignment operator
Definition matrix.h:102
mathematical vector of arbitrary type and size
Definition vector.h:40
vector(void)
Definition vector.h:45
linear algebra implementation