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

matrix_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 // Named arithmetic operators
00027 // 
00028 inline Matrix uplus(const Matrix& a) {
00029   return a;
00030 }
00031 inline Matrix uminus(const Matrix& a) {
00032   return -a;
00033 }
00034 inline Matrix mplus(const Matrix& a, const Matrix& b) {
00035   return a + b;
00036 }
00037 inline Matrix mminus(const Matrix& a, const Matrix& b) {
00038   return a - b;
00039 }
00040 inline MatTimesMat times(const Matrix& a, const Matrix& b) {
00041   return MatTimesMat(a,b);
00042 }
00043 inline MatMTimesMat mtimes(const Matrix& a, const Matrix& b) {
00044   return MatMTimesMat(a,b);
00045 }
00046 inline Matrix rdivide(const Matrix& a, const Matrix& b) {
00047   return ldivide(b,a);
00048 }
00049 inline Matrix mrdivide(Matrix a, Matrix b) {
00050   return a / b;
00051 }
00052 inline MatCrossMat cross(const Matrix& a, const Matrix& b) {
00053   return MatCrossMat(a,b);
00054 }
00055 inline void sincos(Matrix& s, Matrix& c, const Matrix& a) {
00056   s = sin(a); c = cos(a); 
00057   return;
00058 }
00059 
00060 // 
00061 // Indexing
00062 //
00063 inline Matrix subsasgn(const Matrix& a, const Matrix& idx, const Matrix& b) {
00064   return subsasgn(a,idx,Matrix::DIN,b);
00065 }
00066 
00067 //
00068 // Elementary matrices
00069 //
00070 inline Matrix zeros(int n) {
00071   return Matrix(n,n,0.);
00072 }
00073 inline Matrix zeros(int m, int n) {
00074   return Matrix(m,n,0.);
00075 }
00076 inline Matrix zeros(const Matrix& s) {
00077   return Matrix(int(s.ref->re[0]), int(s.ref->re[1]),0.);
00078 }
00079 inline Matrix ones(int n) {
00080   return Matrix(n,n,1.);
00081 }
00082 inline Matrix ones(int m, int n) {
00083   return Matrix(m,n,1.);
00084 }
00085 inline Matrix ones(const Matrix& s) {
00086   return Matrix(int(s.ref->re[0]), int(s.ref->re[1]),1.);
00087 }
00088 inline Matrix eye(int n) {
00089   return eye(n,n);
00090 }
00091 inline Matrix eye(int m, int n) {
00092   Matrix c(m,n,0.);
00093   for (int i=1; i<=min(m,n); i++)
00094     c.ref->index(i,i) = 1;
00095 
00096   return c;
00097 }
00098 inline Matrix eye(const Matrix& s) {
00099   return eye(int(s.ref->re[0]), int(s.ref->re[1]));
00100 }
00101 inline Matrix colon(double start, double step, double stop) {
00102   return ramp(start, step, stop);
00103 }
00104 // inline Matrix colon() {
00105 //   Matrix m(1,1);
00106 
00107 //   m.ref->m = -1; m.ref->n = -1;
00108 //   return m;
00109 // }
00110 
00111 inline Matrix colon() {
00112   return Matrix::COLON;
00113 }
00114 
00115 //
00116 // Matrix information
00117 //
00118 inline int size(int& cols, const Matrix& a) {
00119   cols = a.ref->n;
00120   return a.ref->m;
00121 }
00122 inline int size(const Matrix& a, int dim) {
00123   if (dim == 1)
00124     return a.ref->m;
00125   else if (dim == 2)
00126     return a.ref->n;
00127   else
00128     handle_exception(MatrixException(__FILE__,__LINE__,"In size(A,dim), dim must be either 1 or 2.",));
00129 }
00130 inline Matrix size(const Matrix& a) {
00131   Matrix s(1,2);
00132 
00133   s.ref->index(1) = a.ref->m;
00134   s.ref->index(2) = a.ref->n;
00135 
00136   return s;
00137 }
00138 inline int length(const Matrix& a) {
00139   return a.ref->l;
00140 }
00141 
00142 inline bool isScalar(const Matrix& a) {
00143   return a.IsScalar();
00144 }
00145 
00146 inline Matrix 
00147 mhorzcat(const Matrix& mat1, const Matrix& mat2, const Matrix& mat3,
00148          const Matrix& mat4, const Matrix& mat5, const Matrix& mat6,
00149          const Matrix& mat7, const Matrix& mat8, const Matrix& mat9,
00150          const Matrix& mat10,
00151          const Matrix& mat11, const Matrix& mat12, const Matrix& mat13,
00152          const Matrix& mat14, const Matrix& mat15, const Matrix& mat16,
00153          const Matrix& mat17, const Matrix& mat18, const Matrix& mat19,
00154          const Matrix& mat20) {
00155   return horzcat(mat1,mat2,mat3,mat4,mat5,mat6,mat7,mat8,mat9,
00156                  mat10,mat12,mat13,mat14,mat15,mat16,mat17,mat18,mat19,
00157                  mat20);
00158 }
00159 
00160 inline Matrix 
00161 mvertcat(const Matrix& mat1, const Matrix& mat2, const Matrix& mat3,
00162          const Matrix& mat4, const Matrix& mat5, const Matrix& mat6,
00163          const Matrix& mat7, const Matrix& mat8, const Matrix& mat9,
00164          const Matrix& mat10,
00165          const Matrix& mat11, const Matrix& mat12, const Matrix& mat13,
00166          const Matrix& mat14, const Matrix& mat15, const Matrix& mat16,
00167          const Matrix& mat17, const Matrix& mat18, const Matrix& mat19,
00168          const Matrix& mat20) {
00169   return vertcat(mat1,mat2,mat3,mat4,mat5,mat6,mat7,mat8,mat9,
00170                  mat10,mat12,mat13,mat14,mat15,mat16,mat17,mat18,mat19,
00171                  mat20);
00172 }
00173 #endif

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