vector_LTI.cpp
Go to the documentation of this file.
00001 // $Id: vector_LTI.cpp 29495 2008-08-13 12:57:49Z tdelaet $
00002 // Copyright (C) 2002 Klaas Gadeyne <first dot last at gmail dot com>
00003 
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU Lesser General Public License as published by
00007 // the Free Software Foundation; either version 2.1 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018 //
00019 
00020 #include "../config.h"
00021 #ifdef __MATRIXWRAPPER_LTI__
00022 
00023 #include "vector_LTI.h"
00024 
00025 
00026 using std::cout;
00027 using std::endl;
00028 
00029 
00030 // Constructors
00031 MyColumnVector::ColumnVector() : ltiColumnVector() {}
00032 MyColumnVector::ColumnVector(int num_rows) : ltiColumnVector(num_rows){}
00033 MyColumnVector::ColumnVector(const MyColumnVector& a,
00034                              const MyColumnVector& b)
00035   : ltiColumnVector(a.rows() + b.rows())
00036 {
00037   ltiColumnVector& opl = (*this);
00038 
00039   unsigned int i;
00040 
00041   // copy elements of a to opl
00042   for (i=0; i< a.rows(); i++)
00043     opl.at(i) = a(i+1);
00044 
00045   // copy elements of b to opl
00046   for (i=0; i< b.rows(); i++)
00047     opl.at(a.rows() + i) = b(i+1);
00048 }
00049 
00050 // Create from matrix
00051 MyColumnVector::ColumnVector(const MyMatrix &a)
00052 : ltiColumnVector(a.rows())
00053 {
00054   assert(a.columns() == 1);
00055 
00056   // copy elements of a to opl
00057   ltiColumnVector& opl = (*this);
00058   for (unsigned int i=0; i< a.rows(); i++)
00059     {
00060       opl.at(i) = a(i+1,1);
00061     }
00062 }
00063 
00064 // Destructor
00065 MyColumnVector::~ColumnVector(){}
00066 
00067 // Copy constructor
00068 MyColumnVector::ColumnVector(const MyColumnVector& a) :
00069   ltiColumnVector(a){}
00070 MyColumnVector::ColumnVector(const ltiColumnVector & a) :
00071   ltiColumnVector(a){}
00072 
00073 // Resizing
00074 void MyColumnVector::resize(int num_rows)
00075 {
00076   ltiColumnVector & op1 = (*this);
00077   op1.resize(num_rows);
00078 }
00079 
00080 // Number of Rows / Cols
00081 unsigned int MyColumnVector::rows() const { return this->size();}
00082 unsigned int MyColumnVector::columns() const { return 1;}
00083 
00084 MyColumnVector
00085 MyColumnVector::vectorAdd(const MyColumnVector& v2) const
00086 {
00087   const MyColumnVector& v1 = *this;
00088   MyColumnVector res(v1.rows() + v2.rows());
00089 
00090   for (unsigned int i=0; i<v1.rows(); i++)
00091     res(i) = v1(i);
00092 
00093   for (unsigned int i=0; i<v2.rows(); i++)
00094     res(v1.rows()+i) = v2(i);
00095 
00096   return res;
00097 }
00098 
00099 const bool MyColumnVector::operator==(const MyColumnVector& a) const
00100 {
00101   const ltiColumnVector& op1 = *this;
00102   const ltiColumnVector& op2 = a;
00103   return (op1 == op2);
00104 }
00105 
00106 
00107 // Operators
00108 MyColumnVector & MyColumnVector::operator+= (const MyColumnVector& a)
00109 {
00110   ltiColumnVector & op1 = (*this);
00111   const ltiColumnVector & op2 = a;
00112   op1 += op2;
00113   return (MyColumnVector &) op1 ;
00114 }
00115 
00116 MyColumnVector & MyColumnVector::operator-= (const MyColumnVector& a)
00117 {
00118   ltiColumnVector & op1 = (*this);
00119   const ltiColumnVector & op2 = a;
00120   op1 -= op2;
00121   return (MyColumnVector &) op1 ;
00122 }
00123 
00124 MyColumnVector MyColumnVector::operator+ (const MyColumnVector &a) const
00125 {
00126   ltiColumnVector op1(*this);
00127   const ltiColumnVector & op2 = a;
00128   ltiColumnVector result = (ltiColumnVector) (op1.add(op2));
00129   return (MyColumnVector) result;
00130 }
00131 
00132 MyColumnVector MyColumnVector::operator- (const MyColumnVector &a) const
00133 {
00134   ltiColumnVector op1(*this);
00135   const ltiColumnVector & op2 = a;
00136   ltiColumnVector result = (ltiColumnVector) (op1.subtract(op2));
00137   return (MyColumnVector) result;
00138 }
00139 
00140 
00141 
00142 MyColumnVector& MyColumnVector::operator+= (double a)
00143 {
00144   ltiColumnVector& op1 = *this;
00145   op1 += a;
00146   return (MyColumnVector&) op1;
00147 }
00148 
00149 MyColumnVector& MyColumnVector::operator-= (double a)
00150 {
00151   ltiColumnVector& op1 = *this;
00152   op1 -= a;
00153   return (MyColumnVector&) op1;
00154 }
00155 
00156 
00157 MyColumnVector& MyColumnVector::operator*= (double a)
00158 {
00159   ltiColumnVector& op1 = *this;
00160   op1 *= a;
00161   return (MyColumnVector&) op1;
00162 }
00163 
00164 MyColumnVector& MyColumnVector::operator/= (double a)
00165 {
00166   ltiColumnVector& op1 = *this;
00167   op1 /= a;
00168   return (MyColumnVector&) op1;
00169 }
00170 
00171 
00172 MyColumnVector MyColumnVector::operator+ (double a) const
00173 {
00174   ltiColumnVector op1(*this);
00175   op1 += a;
00176   return (MyColumnVector&) op1;
00177 }
00178 
00179 
00180 MyColumnVector MyColumnVector::operator- (double a) const
00181 {
00182   ltiColumnVector op1(*this);
00183   op1 -= a;
00184   return (MyColumnVector&) op1;
00185 }
00186 
00187 MyColumnVector MyColumnVector::operator* (double a) const
00188 {
00189   ltiColumnVector op1(*this);
00190   return (MyColumnVector) (op1.multiply(a));
00191 }
00192 
00193 
00194 MyColumnVector MyColumnVector::operator/ (double a) const
00195 {
00196   ltiColumnVector op1(*this);
00197   return (MyColumnVector) (op1.divide(a));
00198 }
00199 
00200 
00201 
00202 
00203 
00204 
00205 
00206 MyRowVector MyColumnVector::transpose() const
00207 {
00208   ltiRowVector transposedbase((*this));
00209   return (MyRowVector) transposedbase;
00210 }
00211 
00212 MyMatrix MyColumnVector::operator* (const MyRowVector &a) const
00213 {
00214   const ltiColumnVector& op1 = *this;
00215   const ltiRowVector & op2 = a;
00216   ltiMatrix result(op1.size(),op2.size());
00217   result.outerProduct(op1,op2);
00218   return (MyMatrix) result;
00219 }
00220 
00221 MyColumnVector& MyColumnVector::operator=(const MyColumnVector &a)
00222 {
00223   // Both these implementations result in the same
00224   ltiColumnVector * op1; const ltiColumnVector * op2;
00225   op1 = this; op2 = &a;
00226   *op1 = *op2;
00227 
00228   return *this;
00229 }
00230 
00231 MyColumnVector& MyColumnVector::operator=(const double a)
00232 {
00233   // Both these implementations result in the same
00234   ltiColumnVector * op1;
00235   op1 = this;
00236   (*op1).fill(a,0,(*op1).size());
00237 
00238   return *this;
00239 }
00240 
00241 double &MyColumnVector::operator()(unsigned int i)
00242 {
00243   assert (i != 0);
00244   //ltiColumnVector * op1;
00245   //op1 = this;
00246   return this->at(i-1);
00247 }
00248 
00249 const double MyColumnVector::operator()(unsigned int i) const
00250 {
00251   assert (i != 0);
00252   //ltiColumnVector op1(*this);
00253   return this->at(i-1);
00254 }
00255 
00256 
00257 MyColumnVector MyColumnVector::sub(int j_start , int j_end) const
00258 {
00259   ltiColumnVector result(*this,j_start-1,j_end-1);
00260   return (MyColumnVector) result;
00261 }
00262 
00266 
00267 // Constructors
00268 MyRowVector::RowVector() : ltiRowVector() {}
00269 MyRowVector::RowVector(int num_rows) : ltiRowVector(num_rows){}
00270 
00271 // Destructor
00272 MyRowVector::~RowVector(){}
00273 
00274 // Copy constructor
00275 MyRowVector::RowVector(const MyRowVector& a) : ltiRowVector(a){}
00276 MyRowVector::RowVector(const ltiRowVector & a) : ltiRowVector(a){}
00277 
00278 // Number of Rows / Cols
00279 unsigned int MyRowVector::rows() const { return 1;}
00280 unsigned int MyRowVector::columns() const { return this->size();}
00281 
00282 const bool MyRowVector::operator==(const MyRowVector& a) const
00283 {
00284   const ltiRowVector& op1 = *this;
00285   const ltiRowVector& op2 = a;
00286   return (op1 == op2);
00287 }
00288 
00289 
00290 // Operators
00291 MyRowVector & MyRowVector::operator+= (const MyRowVector& a)
00292 {
00293   ltiRowVector & op1 = (*this);
00294   const ltiRowVector & op2 = a;
00295   op1 += op2;
00296   return (MyRowVector &) op1 ;
00297 }
00298 
00299 MyRowVector & MyRowVector::operator-= (const MyRowVector& a)
00300 {
00301   ltiRowVector & op1 = (*this);
00302   const ltiRowVector & op2 = a;
00303   op1 -= op2;
00304   return (MyRowVector &) op1 ;
00305 }
00306 
00307 MyRowVector MyRowVector::operator+ (const MyRowVector &a) const
00308 {
00309   ltiRowVector op1(*this);
00310   const ltiRowVector & op2 = a;
00311   ltiRowVector result = (ltiRowVector) (op1.add(op2));
00312   return (MyRowVector) result;
00313 }
00314 
00315 MyRowVector MyRowVector::operator- (const MyRowVector &a) const
00316 {
00317   ltiRowVector op1(*this);
00318   const ltiRowVector & op2 = a;
00319   ltiRowVector result = (ltiRowVector) (op1.subtract(op2));
00320   return (MyRowVector) result;
00321 }
00322 
00323 
00324 
00325 
00326 
00327 
00328 MyRowVector& MyRowVector::operator+= (double a)
00329 {
00330   ltiRowVector& op1 = *this;
00331   op1 += a;
00332   return (MyRowVector&) op1;
00333 }
00334 
00335 MyRowVector& MyRowVector::operator-= (double a)
00336 {
00337   ltiRowVector& op1 = *this;
00338   op1 -= a;
00339   return (MyRowVector&) op1;
00340 }
00341 
00342 
00343 MyRowVector& MyRowVector::operator*= (double a)
00344 {
00345   ltiRowVector& op1 = *this;
00346   op1 *= a;
00347   return (MyRowVector&) op1;
00348 }
00349 
00350 MyRowVector& MyRowVector::operator/= (double a)
00351 {
00352   ltiRowVector& op1 = *this;
00353   op1 /= a;
00354   return (MyRowVector&) op1;
00355 }
00356 
00357 
00358 MyRowVector MyRowVector::operator+ (double a) const
00359 {
00360   ltiRowVector op1(*this);
00361   op1 += a;
00362   return (MyRowVector&) op1;
00363 }
00364 
00365 
00366 MyRowVector MyRowVector::operator- (double a) const
00367 {
00368   ltiRowVector op1(*this);
00369   op1 -= a;
00370   return (MyRowVector&) op1;
00371 }
00372 
00373 MyRowVector MyRowVector::operator* (double a) const
00374 {
00375   ltiRowVector op1(*this);
00376   return (MyRowVector) (op1.multiply(a));
00377 }
00378 
00379 
00380 MyRowVector MyRowVector::operator/ (double a) const
00381 {
00382   ltiRowVector op1(*this);
00383   return (MyRowVector) (op1.divide(a));
00384 }
00385 
00386 MyRowVector MyRowVector::operator*(const MyMatrix& a)
00387 {
00388   assert(this->columns() == a.rows());
00389 
00390   ltiRowVector & op1 = (*this);
00391   const ltiMatrix & op2 = a;
00392   ltiRowVector result = op2.leftMultiply(op1);
00393   return (MyRowVector) result;
00394 }
00395 
00396 
00397 double MyRowVector::operator*(const MyColumnVector& a) const
00398 {
00399   assert(this->columns() == a.rows());
00400 
00401   const ltiRowVector & op1 = (*this);
00402   const ltiColumnVector & op2 = a;
00403   double result=op1.dot(op2);
00404   return result;
00405 }
00406 
00407 MyRowVector& MyRowVector::operator=(const MyRowVector &a)
00408 {
00409   // Both these implementations result in the same
00410   ltiRowVector * op1;
00411   const ltiRowVector * op2;
00412   op1 = this;
00413   op2 = &a;
00414   *op1 = *op2;
00415 
00416   return *this;
00417 }
00418 
00419 
00420 MyRowVector& MyRowVector::operator=(const double a)
00421 {
00422   // Both these implementations result in the same
00423   ltiRowVector * op1;
00424   op1 = this;
00425   (*op1).fill(a,0,(*op1).size());
00426 
00427   return *this;
00428 }
00429 
00430 
00431 MyColumnVector MyRowVector::transpose() const
00432 {
00433   ltiColumnVector transposedbase((*this));
00434   return (MyColumnVector) transposedbase;
00435 }
00436 
00437 
00438 double &MyRowVector::operator()(unsigned int i)
00439 {
00440   assert (i != 0);
00441   ltiRowVector * op1;
00442   op1 = this;
00443   return op1->at(i-1);
00444 }
00445 
00446 const double MyRowVector::operator()(unsigned int i) const
00447 {
00448   assert (i != 0);
00449   ltiRowVector op1(*this);
00450   return ((op1.at(i-1)));
00451 }
00452 
00453 
00454 
00455 MyRowVector MyRowVector::sub(int j_start , int j_end) const
00456 {
00457   ltiRowVector result(*this,j_start-1,j_end-1);
00458   return (MyRowVector) result;
00459 }
00460 
00461 // Resizing
00462 void MyRowVector::resize(int num_cols)
00463 {
00464   ltiRowVector & op1 = (*this);
00465   op1.resize(num_cols);
00466 }
00467 
00468 
00469 
00470 MyRowVector
00471 MyRowVector::vectorAdd(const MyRowVector& v2) const
00472 {
00473   const MyRowVector& v1 = *this;
00474   MyRowVector res(v1.columns() + v2.columns());
00475 
00476   for (unsigned int i=0; i<v1.columns(); i++)
00477     res(i) = v1(i);
00478 
00479   for (unsigned int i=0; i<v2.columns(); i++)
00480     res(v1.columns()+i) = v2(i);
00481 
00482   return res;
00483 }
00484 
00485 #endif


bfl
Author(s): Klaas Gadeyne, Wim Meeussen, Tinne Delaet and many others. See web page for a full contributor list. ROS package maintained by Wim Meeussen.
autogenerated on Thu Feb 11 2016 22:31:57