Peano 4
Loading...
Searching...
No Matches
MatrixOperations.cpph
Go to the documentation of this file.
1template<int Rows, typename Scalar>
4
5 for (int i=0; i<Rows; i++) {
6 result(i,i) = 1.0;
7 }
8
9 return result;
10}
11
12
13template<int Rows, int Cols, typename Scalar>
16) {
17 Scalar result(0);
18
19 for (int row=0; row<Rows; row++)
20 for (int col=0; col<Cols; col++) {
21 result += matrix(row,col) * matrix(row,col);
22 }
23
24 return std::sqrt(result);
25}
26
27
28template<int Rows, int Cols, typename Scalar>
31) {
32 Scalar result(0);
33
34 for (int row=0; row<Rows; row++)
35 for (int col=0; col<Cols; col++) {
36 result = std::max( result, std::abs( matrix(row,col) ) );
37 }
38
39 return result;
40}
41
42
43template<int Rows, int Cols, typename Scalar>
46) {
48
49 for (int i=0; i<Rows; i++) {
50 for (int j=0; j<Cols; j++) {
51 result(i,j) = 1.0/matrix(i,j);
52 }
53 }
54
55 return result;
56}
57
58
59
60template<int Rows, int Cols, typename Scalar>
61tarch::la::Vector<Cols,Scalar> tarch::la::row(const Matrix<Rows,Cols,Scalar>& matrix, int whichRow) {
63
64 for (int i=0; i<Cols; i++) {
65 result(i) = matrix(whichRow,i);
66 }
67
68 return result;
69}
70
71
72template<int Rows, int Cols, typename Scalar>
73tarch::la::Vector<Rows,Scalar> tarch::la::col(const Matrix<Rows,Cols,Scalar>& matrix, int whichColumn) {
75
76 for (int i=0; i<Rows; i++) {
77 result(i) = matrix(i,whichColumn);
78 }
79
80 return result;
81}
82
83
84template<int Rows, int Cols, typename Scalar>
87 #ifdef CompilerICC
88 #pragma ivdep
89 #endif
90 for (int i=0; i < Rows; i++) {
91 for (int j=0; j < Cols; j++) {
92 result(j,i) += matrix(i,j);
93 }
94 }
95 return result;
96}
97
98
99
100template<int Rows, int Cols, typename Scalar>
102 Scalar result = 0;
103 for (int i=0; i < Rows; i++) {
104 for (int j=0; j < Cols; j++) {
105 result += matrix(i,j);
106 }
107 }
108 return result;
109}
110
111
112
113template<int Rows, int Cols, typename Scalar>
114std::ostream& operator<< (
115 std::ostream& os,
117) {
118 os << matrix.toString();
119 return os;
120}
121
122
123template<int Rows, typename Scalar>
124tarch::la::Vector<Rows,Scalar> tarch::la::diag(const Matrix<Rows,Rows,Scalar>& matrix) {
126 for (int i=0; i<Rows; i++) {
127 result(i) = matrix(i,i);
128 }
129 return result;
130}
131
And from this we can write down f$ nabla phi_i nabla phi_i dx but since we are constructing matrix let s investigate the f$ our matrix elements will nabla phi_i dx f By this will be a sparse matrix
And from this we can write down f$ nabla phi_i nabla phi_i dx but since we are constructing matrix let s investigate the f$ j
std::ostream & operator<<(std::ostream &os, const tarch::la::Matrix< Rows, Cols, Scalar > &matrix)
Static (i.e.
Definition Matrix.h:31
int i
Definition makeIC.py:51
Matrix< Cols, Rows, Scalar > transpose(const Matrix< Rows, Cols, Scalar > &matrix)
Scalar sum(const Matrix< Rows, Cols, Scalar > &matrix)
Computes the sum of all entries of the matrix.
Vector< Rows, Scalar > col(const Matrix< Rows, Cols, Scalar > &matrix, int whichColumn)
Extract row from matrix.
Scalar elementMax(const Matrix< Rows, Cols, Scalar > &matrix)
Max norm.
Vector< Rows, Scalar > diag(const Matrix< Rows, Rows, Scalar > &matrix)
Extract diagonal vector from matrix.
Matrix< Rows, Cols, Scalar > invertEntries(const Matrix< Rows, Cols, Scalar > &matrix)
static Matrix< Rows, Rows, Scalar > identity()
Returns the identity matrix.
Vector< Cols, Scalar > row(const Matrix< Rows, Cols, Scalar > &matrix, int whichRow)
Extract row from matrix.
Scalar frobeniusNorm(const Matrix< Rows, Cols, Scalar > &matrix)
Simple vector class.
Definition Vector.h:134