Carmen Code
 All Classes Files Functions Variables Macros Pages
Matrix.h
Go to the documentation of this file.
1 /***************************************************************************
2  Matrix.h - description
3  -------------------
4  begin : mer fév 11 2004
5  copyright : (C) 2004 by Olivier Roussel and Alexei Tsigulin
6  email : roussel@ict.uni-karlsruhe.de; lpsoft@mail.ru
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
28 class Matrix
29 {
30 
31 /*
32 ______________________________________________________________________________________________
33 
34  Constructor and distructor
35 ______________________________________________________________________________________________
36 
37 */
38 
39 public:
52  Matrix();
53 
64 Matrix(const int i, const int j);
65 
76 Matrix(const int i);
77 
89 Matrix(const Matrix& M);
90 
102 Matrix(const Vector& V);
103 
109 ~Matrix();
110 /*
111 ______________________________________________________________________________________________
112 
113  Set and get
114 ______________________________________________________________________________________________
115 
116 */
117 
136 inline void setValue(const int i, const int j, const real a);
137 
143 void setZero();
144 
163 inline real value(const int i, const int j) const;
164 
170 inline int lines() const;
171 
177 inline int columns() const;
178 /*
179 ______________________________________________________________________________________________
180 
181  Operators
182 ______________________________________________________________________________________________
183 
184 */
185 
203 bool operator== (const Matrix& M ) const;
204 
220 void operator= (const Matrix& M );
221 
237 void operator+=(const Matrix& M );
238 
255 Matrix operator+ (const Matrix& M ) const;
256 
272 void operator-=(const Matrix& M );
273 
290 Matrix operator- (const Matrix& M ) const;
291 
306 Matrix operator- () const;
307 
323 void operator*=(const real a );
324 
343 Matrix operator* (const real a ) const;
344 
360 void operator/=(const real a );
361 
378 Matrix operator/ (const real a ) const;
379 
396 Matrix operator* (const Matrix& M ) const;
397 
414 Vector operator* (const Vector& V) const;
415 
426 void setEigenMatrix(const bool isLeft, const int AxisNo, const Vector V, const real c, const real h=0.);
427 /*
428 ______________________________________________________________________________________________
429 
430 PRIVATE VARIABLES
431 ______________________________________________________________________________________________
432 
433 */
434 //parallel modification
435 //private:
436 public:
437  int Lines, Columns;
438  real *U;
439 };
440 
441 /*
442 ______________________________________________________________________________________________
443 
444 EXTERNAL FUNCTIONS
445 ______________________________________________________________________________________________
446 
447 */
448 
468 Matrix operator* (const real a, const Matrix& M);
469 
477 ostream& operator<<(ostream& out, const Matrix& M);
478 
479 /*
480 ______________________________________________________________________________________________
481 
482 INLINE FUNCTIONS
483 ______________________________________________________________________________________________
484 */
485 
486 inline int Matrix::lines() const
487 {
488  return Lines;
489 }
490 /*
491 ______________________________________________________________________________________________
492 
493 */
494 
495 inline int Matrix::columns() const
496 {
497  return Columns;
498 }
499 
500 /*
501 ______________________________________________________________________________________________
502 
503 */
504 
505 inline void Matrix::setValue(const int i, const int j, const real a)
506 {
507  *( U + (i-1)*Columns + (j-1) ) = a;
508 }
509 
510 /*
511 ______________________________________________________________________________________________
512 
513 */
514 
515 inline real Matrix::value(const int i, const int j) const
516 {
517  return *(U+(i-1)*Columns+(j-1));
518 }
519 
void operator*=(const real a)
Multiplies the current matrix by a real a.
Definition: Matrix.cpp:268
void operator-=(const Matrix &M)
Subtracts M to the current matrix.
Definition: Matrix.cpp:220
void operator=(const Matrix &M)
Set the current matrix to the dimension and the value of M.
Definition: Matrix.cpp:161
Matrix()
Constructor of matrix class. Generates a 1,1 matrix equal to zero.
Definition: Matrix.cpp:30
Standard class for every vector in Carmen.
Definition: Vector.h:29
real * U
Definition: Matrix.h:438
void operator/=(const real a)
Divides the current matrix by a real a.
Definition: Matrix.cpp:299
real value(const int i, const int j) const
Returns the value of the component i, j.
Definition: Matrix.h:515
Matrix operator/(const real a) const
Returns the division of the current matrix by a real a.
Definition: Matrix.cpp:312
Matrix operator*(const real a) const
Returns the product of the current matrix and a real a.
Definition: Matrix.cpp:280
void setZero()
Sets all the components to zero.
Definition: Matrix.cpp:127
Matrix operator+(const Matrix &M) const
Returns the addition of the current matrix and M.
Definition: Matrix.cpp:201
void operator+=(const Matrix &M)
Adds M to the current matrix.
Definition: Matrix.cpp:187
int Columns
Definition: Matrix.h:437
Standard class for every matrix in Carmen.
Definition: Matrix.h:28
Matrix operator*(const real a, const Matrix &M)
Returns the product of the current matrix and a real a.
Definition: Matrix.cpp:1040
int lines() const
Returns the number of lines of the matrix.
Definition: Matrix.h:486
int columns() const
Returns the number of columns of the matrix.
Definition: Matrix.h:495
void setValue(const int i, const int j, const real a)
Sets the component i, j to value a.
Definition: Matrix.h:505
Matrix operator-() const
Returns the opposite of the current matrix.
Definition: Matrix.cpp:249
ostream & operator<<(ostream &out, const Matrix &M)
Writes the components of the matrix M on screen.
Definition: Matrix.cpp:1053
void setEigenMatrix(const bool isLeft, const int AxisNo, const Vector V, const real c, const real h=0.)
Sets matrix as eigenmatrix.
Definition: Matrix.cpp:370
bool operator==(const Matrix &M) const
Compares the current matrix to a matrix M and returns true if they are equal.
Definition: Matrix.cpp:143
int Lines
Definition: Matrix.h:437
#define real
Definition: PreProcessor.h:31
~Matrix()
Distructor of matrix class. Deallocate memory of the matrix.
Definition: Matrix.cpp:112