Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

matrix_friend_ops_inline.hh

Go to the documentation of this file.
00001 #ifndef _MATRIX_FRIEND_OPS_INLINE_HH_
00002 #define _MATRIX_FRIEND_OPS_INLINE_HH_
00003 
00004 // This header contains the inline definitions of the matrix operations.
00005 // It is designed to be included in matrix.hh and should not be used on
00006 // its own.  Definitions of matrix operations not included here are found
00007 // in matrix.cc.
00008 
00009 // 
00010 // Arithmetic operators
00011 //
00012 inline Matrix operator + (const Matrix& a) {
00013   return a;
00014 }
00015 inline MatMTimesMat operator * (const Matrix& a, const Matrix& b) {
00016   return MatMTimesMat(a,b);
00017 }
00018 inline Matrix operator / (const Matrix& a, const Matrix& b) {
00019   if (b.IsScalar()) 
00020     return ldivide(b,a);
00021   else 
00022     return ctranspose(mldivide(ctranspose(b),ctranspose(a)));
00023 }
00024 
00025 //
00026 // comparison operators
00027 //
00028 // inline bool operator != (const Matrix& a, const Matrix& b) {
00029 //   return !(a == b);
00030 // }
00031 
00032 // inline bool operator <= (const Matrix& a, const Matrix& b) {
00033 //   return !(a > b);
00034 // }
00035 
00036 // inline bool operator >= (const Matrix& a, const Matrix& b) {
00037 //   return !(a < b);
00038 // }
00039 
00040 // 
00041 // Named arithmetic operators
00042 // 
00043 inline Matrix uplus(const Matrix& a) {
00044   return a;
00045 }
00046 inline Matrix uminus(const Matrix& a) {
00047   return -a;
00048 }
00049 inline Matrix mplus(const Matrix& a, const Matrix& b) {
00050   return a + b;
00051 }
00052 inline Matrix mminus(const Matrix& a, const Matrix& b) {
00053   return a - b;
00054 }
00055 inline MatTimesMat times(const Matrix& a, const Matrix& b) {
00056   return MatTimesMat(a,b);
00057 }
00058 inline MatMTimesMat mtimes(const Matrix& a, const Matrix& b) {
00059   return MatMTimesMat(a,b);
00060 }
00061 inline Matrix rdivide(const Matrix& a, const Matrix& b) {
00062   return ldivide(b,a);
00063 }
00064 inline Matrix mrdivide(Matrix a, Matrix b) {
00065   return a / b;
00066 }
00067 inline MatCrossMat cross(const Matrix& a, const Matrix& b) {
00068   return MatCrossMat(a,b);
00069 }
00070 inline Matrix sincos(Matrix& c, const Matrix& a) {
00071   c = cos(a); 
00072   return sin(a);
00073 }
00074 
00075 // 
00076 // Indexing
00077 //
00078 inline Matrix subsasgn(const Matrix& a, const Matrix& idx, const Matrix& b) {
00079   return subsasgn(a,idx,Matrix::DIN,b);
00080 }
00081 
00082 //
00083 // Elementary matrices
00084 //
00085 inline Matrix zeros(int n) {
00086   return Matrix(n,n,0.);
00087 }
00088 inline Matrix zeros(int m, int n) {
00089   return Matrix(m,n,0.);
00090 }
00091 inline Matrix zeros(const Matrix& s) {
00092   return Matrix(int(s.ref->re[0]), int(s.ref->re[1]),0.);
00093 }
00094 inline Matrix ones(int n) {
00095   return Matrix(n,n,1.);
00096 }
00097 inline Matrix ones(int m, int n) {
00098   return Matrix(m,n,1.);
00099 }
00100 inline Matrix ones(const Matrix& s) {
00101   return Matrix(int(s.ref->re[0]), int(s.ref->re[1]),1.);
00102 }
00103 inline Matrix eye(int n) {
00104   return eye(n,n);
00105 }
00106 inline Matrix eye(int m, int n) {
00107   Matrix c(m,n,0.);
00108   for (int i=1; i<=min(m,n); i++)
00109     c.ref->index(i,i) = 1;
00110 
00111   return c;
00112 }
00113 inline Matrix eye(const Matrix& s) {
00114   return eye(int(s.ref->re[0]), int(s.ref->re[1]));
00115 }
00116 inline Matrix colon(double start, double step, double stop) {
00117   return ramp(start, step, stop);
00118 }
00119 // inline Matrix colon() {
00120 //   Matrix m(1,1);
00121 
00122 //   m.ref->m = -1; m.ref->n = -1;
00123 //   return m;
00124 // }
00125 
00126 inline Matrix colon() {
00127   return Matrix::COLON;
00128 }
00129 
00130 //
00131 // Matrix information
00132 //
00133 inline int size(int& cols, const Matrix& a) {
00134   cols = a.ref->n;
00135   return a.ref->m;
00136 }
00137 inline int size(const Matrix& a, int dim) {
00138   if (dim == 1)
00139     return a.ref->m;
00140   else if (dim == 2)
00141     return a.ref->n;
00142   else
00143     handle_exception(MatrixException(__FILE__,__LINE__,"In size(A,dim), dim must be either 1 or 2."));
00144 }
00145 inline Matrix size(const Matrix& a) {
00146   Matrix s(1,2);
00147 
00148   s.ref->index(1) = a.ref->m;
00149   s.ref->index(2) = a.ref->n;
00150 
00151   return s;
00152 }
00153 inline int length(const Matrix& a) {
00154   return a.ref->l;
00155 }
00156 
00157 inline bool isScalar(const Matrix& a) {
00158   return a.IsScalar();
00159 }
00160 
00161 inline Matrix 
00162 mhorzcat(const Matrix& mat1, const Matrix& mat2, const Matrix& mat3,
00163          const Matrix& mat4, const Matrix& mat5, const Matrix& mat6,
00164          const Matrix& mat7, const Matrix& mat8, const Matrix& mat9,
00165          const Matrix& mat10,
00166          const Matrix& mat11, const Matrix& mat12, const Matrix& mat13,
00167          const Matrix& mat14, const Matrix& mat15, const Matrix& mat16,
00168          const Matrix& mat17, const Matrix& mat18, const Matrix& mat19,
00169          const Matrix& mat20) {
00170   return horzcat(mat1,mat2,mat3,mat4,mat5,mat6,mat7,mat8,mat9,
00171                  mat10,mat12,mat13,mat14,mat15,mat16,mat17,mat18,mat19,
00172                  mat20);
00173 }
00174 
00175 inline Matrix 
00176 mvertcat(const Matrix& mat1, const Matrix& mat2, const Matrix& mat3,
00177          const Matrix& mat4, const Matrix& mat5, const Matrix& mat6,
00178          const Matrix& mat7, const Matrix& mat8, const Matrix& mat9,
00179          const Matrix& mat10,
00180          const Matrix& mat11, const Matrix& mat12, const Matrix& mat13,
00181          const Matrix& mat14, const Matrix& mat15, const Matrix& mat16,
00182          const Matrix& mat17, const Matrix& mat18, const Matrix& mat19,
00183          const Matrix& mat20) {
00184   return vertcat(mat1,mat2,mat3,mat4,mat5,mat6,mat7,mat8,mat9,
00185                  mat10,mat12,mat13,mat14,mat15,mat16,mat17,mat18,mat19,
00186                  mat20);
00187 }
00188 #endif

Generated on Wed Jun 18 09:16:20 2003 for admc++ by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002