1 //////////////////////////////////////////////////////////////////////////////
4 // ADLib, Prop and their related set of tools and documentation are in the
5 // public domain. The author(s) of this software reserve no copyrights on
6 // the source code and any code generated using the tools. You are encouraged
7 // to use ADLib and Prop to develop software, in both academic and commercial
8 // settings, and are free to incorporate any part of ADLib and Prop into
11 // Although you are under no obligation to do so, we strongly recommend that
12 // you give away all software developed using our tools.
14 // We also ask that credit be given to us when ADLib and/or Prop are used in
15 // your programs, and that this notice be preserved intact in all the source
18 // This software is still under development and we welcome any suggestions
19 // and help from the users.
23 //////////////////////////////////////////////////////////////////////////////
25 #ifndef floating_point_matrix_h
26 #define floating_point_matrix_h
29 #include <AD/contain/array2.h> // two dimensional arrays
31 //////////////////////////////////////////////////////////////////////
32 // Class Matrix is inherited from the two dimensional array class
34 //////////////////////////////////////////////////////////////////////
35 class Matrix
: public Array2
<double> {
37 void can_add(const Matrix
&) const; // check whether addition is defined.
38 void can_mult(const Matrix
&) const; // check whether multiplication is defined.
42 //////////////////////////////////////////////////////////////////
43 // Default error handler
44 //////////////////////////////////////////////////////////////////
45 static void (*error
)(const char [], ...);
47 //////////////////////////////////////////////////////////////////
48 // Constructor and destructors
49 //////////////////////////////////////////////////////////////////
51 Matrix(int m
, int n
) : Array2
<double>(m
,n
) {}
52 Matrix(int m
, int n
, double e
) : Array2
<double>(m
,n
,e
) {}
53 Matrix(const Matrix
& m
) : Array2
<double>(m
) {}
56 //////////////////////////////////////////////////////////////////
58 //////////////////////////////////////////////////////////////////
59 Matrix
& operator = (const Matrix
& a
) { Array2
<double>::operator = (a
); return *this; }
60 Matrix
& operator = (double e
) { Array2
<double>::operator = (e
); return *this; }
62 //////////////////////////////////////////////////////////////////
63 // Selectors, indexing etc.
64 // Inherited from base class
65 //////////////////////////////////////////////////////////////////
67 // int columns() const;
68 // const double * operator [] (int i) const;
69 // double * operator [] (int i);
71 //////////////////////////////////////////////////////////////////
73 //////////////////////////////////////////////////////////////////
75 friend Matrix
operator + (double, const Matrix
&);
76 friend Matrix
operator + (const Matrix
&, double);
77 friend Matrix
operator - (double, const Matrix
&);
78 friend Matrix
operator - (const Matrix
&, double);
79 friend Matrix
operator * (double, const Matrix
&);
80 friend Matrix
operator * (const Matrix
&, double);
81 friend Matrix
operator / (const Matrix
&, double);
83 //////////////////////////////////////////////////////////////////
84 // In place scalar operations
85 //////////////////////////////////////////////////////////////////
87 Matrix
& operator += (double);
88 Matrix
& operator -= (double);
89 Matrix
& operator *= (double);
90 Matrix
& operator /= (double);
92 //////////////////////////////////////////////////////////////////
94 //////////////////////////////////////////////////////////////////
95 friend Matrix
operator + (const Matrix
&, const Matrix
&);
96 friend Matrix
operator - (const Matrix
&, const Matrix
&);
97 friend Matrix
operator * (const Matrix
&, const Matrix
&);
99 Matrix
inverse() const;
101 //////////////////////////////////////////////////////////////////
102 // In place matrix operations
103 //////////////////////////////////////////////////////////////////
104 Matrix
& operator += (const Matrix
& m
);
105 Matrix
& operator -= (const Matrix
& m
);
106 Matrix
& operator *= (const Matrix
& m
);
109 //////////////////////////////////////////////////////////////////
110 // Linear algebra stuff
111 //////////////////////////////////////////////////////////////////
112 Matrix
& LU (const Matrix
&);
116 //////////////////////////////////////////////////////////////////
118 //////////////////////////////////////////////////////////////////
119 friend Bool
operator == (const Matrix
& a
, const Matrix
& b
);
120 friend Bool
operator != (const Matrix
& a
, const Matrix
& b
)
121 { return ! (a
== b
); }
123 //////////////////////////////////////////////////////////////////
124 // Submatrices and slicing
125 //////////////////////////////////////////////////////////////////
127 //////////////////////////////////////////////////////////////////
129 //////////////////////////////////////////////////////////////////
130 friend std::ostream
& operator << (std::ostream
&, const Matrix
&);
131 friend std::istream
& operator >> (std::istream
&, Matrix
&);