ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/math/SquareMatrix.hpp
(Generate patch)

Comparing trunk/OOPSE-2.0/src/math/SquareMatrix.hpp (file contents):
Revision 1616 by tim, Wed Oct 20 18:07:08 2004 UTC vs.
Revision 1630 by tim, Thu Oct 21 21:31:39 2004 UTC

# Line 45 | Line 45 | namespace oopse {
45      template<typename Real, int Dim>
46      class SquareMatrix : public RectMatrix<Real, Dim, Dim> {
47          public:
48 +            typedef Real ElemType;
49 +            typedef Real* ElemPoinerType;
50  
51 <        /** default constructor */
52 <        SquareMatrix() {
53 <            for (unsigned int i = 0; i < Dim; i++)
54 <                for (unsigned int j = 0; j < Dim; j++)
55 <                    data_[i][j] = 0.0;
56 <         }
51 >            /** default constructor */
52 >            SquareMatrix() {
53 >                for (unsigned int i = 0; i < Dim; i++)
54 >                    for (unsigned int j = 0; j < Dim; j++)
55 >                        data_[i][j] = 0.0;
56 >             }
57  
58 <        /** copy constructor */
59 <        SquareMatrix(const RectMatrix<Real, Dim, Dim>& m)  : RectMatrix<Real, Dim, Dim>(m) {
60 <        }
59 <        
60 <        /** copy assignment operator */
61 <        SquareMatrix<Real, Dim>& operator =(const RectMatrix<Real, Dim, Dim>& m) {
62 <            RectMatrix<Real, Dim, Dim>::operator=(m);
63 <            return *this;
64 <        }
65 <                              
66 <        /** Retunrs  an identity matrix*/
67 <
68 <       static SquareMatrix<Real, Dim> identity() {
69 <            SquareMatrix<Real, Dim> m;
58 >            /** copy constructor */
59 >            SquareMatrix(const RectMatrix<Real, Dim, Dim>& m) : RectMatrix<Real, Dim, Dim>(m) {
60 >            }
61              
62 <            for (unsigned int i = 0; i < Dim; i++)
63 <                for (unsigned int j = 0; j < Dim; j++)
64 <                    if (i == j)
65 <                        m(i, j) = 1.0;
66 <                    else
67 <                        m(i, j) = 0.0;
62 >            /** copy assignment operator */
63 >            SquareMatrix<Real, Dim>& operator =(const RectMatrix<Real, Dim, Dim>& m) {
64 >                RectMatrix<Real, Dim, Dim>::operator=(m);
65 >                return *this;
66 >            }
67 >                                  
68 >            /** Retunrs  an identity matrix*/
69  
70 <            return m;
71 <        }
70 >           static SquareMatrix<Real, Dim> identity() {
71 >                SquareMatrix<Real, Dim> m;
72 >                
73 >                for (unsigned int i = 0; i < Dim; i++)
74 >                    for (unsigned int j = 0; j < Dim; j++)
75 >                        if (i == j)
76 >                            m(i, j) = 1.0;
77 >                        else
78 >                            m(i, j) = 0.0;
79  
80 <        /**
81 <         * Retunrs  the inversion of this matrix.
83 <         * @todo need implementation
84 <         */
85 <         SquareMatrix<Real, Dim>  inverse() {
86 <             SquareMatrix<Real, Dim> result;
80 >                return m;
81 >            }
82  
83 <             return result;
84 <        }        
83 >            /**
84 >             * Retunrs  the inversion of this matrix.
85 >             * @todo need implementation
86 >             */
87 >             SquareMatrix<Real, Dim>  inverse() {
88 >                 SquareMatrix<Real, Dim> result;
89  
90 <        /**
91 <         * Returns the determinant of this matrix.
93 <         * @todo need implementation
94 <         */
95 <        Real determinant() const {
96 <            Real det;
97 <            return det;
98 <        }
90 >                 return result;
91 >            }        
92  
93 <        /** Returns the trace of this matrix. */
94 <        Real trace() const {
95 <           Real tmp = 0;
96 <          
97 <            for (unsigned int i = 0; i < Dim ; i++)
98 <                tmp += data_[i][i];
93 >            /**
94 >             * Returns the determinant of this matrix.
95 >             * @todo need implementation
96 >             */
97 >            Real determinant() const {
98 >                Real det;
99 >                return det;
100 >            }
101  
102 <            return tmp;
103 <        }
102 >            /** Returns the trace of this matrix. */
103 >            Real trace() const {
104 >               Real tmp = 0;
105 >              
106 >                for (unsigned int i = 0; i < Dim ; i++)
107 >                    tmp += data_[i][i];
108  
109 <        /** Tests if this matrix is symmetrix. */            
110 <        bool isSymmetric() const {
111 <            for (unsigned int i = 0; i < Dim - 1; i++)
112 <                for (unsigned int j = i; j < Dim; j++)
113 <                    if (fabs(data_[i][j] - data_[j][i]) > oopse::epsilon)
114 <                        return false;
115 <                    
116 <            return true;
117 <        }
109 >                return tmp;
110 >            }
111 >
112 >            /** Tests if this matrix is symmetrix. */            
113 >            bool isSymmetric() const {
114 >                for (unsigned int i = 0; i < Dim - 1; i++)
115 >                    for (unsigned int j = i; j < Dim; j++)
116 >                        if (fabs(data_[i][j] - data_[j][i]) > oopse::epsilon)
117 >                            return false;
118 >                        
119 >                return true;
120 >            }
121  
122 <        /** Tests if this matrix is orthogonal. */            
123 <        bool isOrthogonal() {
124 <            SquareMatrix<Real, Dim> tmp;
122 >            /** Tests if this matrix is orthogonal. */            
123 >            bool isOrthogonal() {
124 >                SquareMatrix<Real, Dim> tmp;
125  
126 <            tmp = *this * transpose();
126 >                tmp = *this * transpose();
127  
128 <            return tmp.isDiagonal();
129 <        }
128 >                return tmp.isDiagonal();
129 >            }
130  
131 <        /** Tests if this matrix is diagonal. */
132 <        bool isDiagonal() const {
133 <            for (unsigned int i = 0; i < Dim ; i++)
134 <                for (unsigned int j = 0; j < Dim; j++)
135 <                    if (i !=j && fabs(data_[i][j]) > oopse::epsilon)
136 <                        return false;
137 <                    
138 <            return true;
139 <        }
131 >            /** Tests if this matrix is diagonal. */
132 >            bool isDiagonal() const {
133 >                for (unsigned int i = 0; i < Dim ; i++)
134 >                    for (unsigned int j = 0; j < Dim; j++)
135 >                        if (i !=j && fabs(data_[i][j]) > oopse::epsilon)
136 >                            return false;
137 >                        
138 >                return true;
139 >            }
140  
141 <        /** Tests if this matrix is the unit matrix. */
142 <        bool isUnitMatrix() const {
143 <            if (!isDiagonal())
142 <                return false;
143 <            
144 <            for (unsigned int i = 0; i < Dim ; i++)
145 <                if (fabs(data_[i][i] - 1) > oopse::epsilon)
141 >            /** Tests if this matrix is the unit matrix. */
142 >            bool isUnitMatrix() const {
143 >                if (!isDiagonal())
144                      return false;
145                  
146 <            return true;
147 <        }        
146 >                for (unsigned int i = 0; i < Dim ; i++)
147 >                    if (fabs(data_[i][i] - 1) > oopse::epsilon)
148 >                        return false;
149 >                    
150 >                return true;
151 >            }        
152  
153 <        /** @todo need implementation */
154 <        void diagonalize() {
155 <            //jacobi(m, eigenValues, ortMat);
156 <        }
153 >            /** @todo need implementation */
154 >            void diagonalize() {
155 >                //jacobi(m, eigenValues, ortMat);
156 >            }
157  
158 <        /**
159 <         * Jacobi iteration routines for computing eigenvalues/eigenvectors of
160 <         * real symmetric matrix
161 <         *
162 <         * @return true if success, otherwise return false
163 <         * @param a symmetric matrix whose eigenvectors are to be computed. On return, the matrix is
164 <         *     overwritten
165 <         * @param w will contain the eigenvalues of the matrix On return of this function
166 <         * @param v the columns of this matrix will contain the eigenvectors. The eigenvectors are
167 <         *    normalized and mutually orthogonal.
168 <         */
169 <      
170 <        static int jacobi(SquareMatrix<Real, Dim>& a, Vector<Real, Dim>& d,
171 <                              SquareMatrix<Real, Dim>& v);
158 >            /**
159 >             * Jacobi iteration routines for computing eigenvalues/eigenvectors of
160 >             * real symmetric matrix
161 >             *
162 >             * @return true if success, otherwise return false
163 >             * @param a symmetric matrix whose eigenvectors are to be computed. On return, the matrix is
164 >             *     overwritten
165 >             * @param w will contain the eigenvalues of the matrix On return of this function
166 >             * @param v the columns of this matrix will contain the eigenvectors. The eigenvectors are
167 >             *    normalized and mutually orthogonal.
168 >             */
169 >          
170 >            static int jacobi(SquareMatrix<Real, Dim>& a, Vector<Real, Dim>& d,
171 >                                  SquareMatrix<Real, Dim>& v);
172      };//end SquareMatrix
173  
174  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines