vector_LTI.cpp
Go to the documentation of this file.
00001 // $Id$
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 // Assign
00081 void MyColumnVector::assign(int num_rows, double value)
00082 {
00083   BoostColumnVector & op1 = (*this);
00084   op1.resize(num_rows);
00085   for (unsigned int i=0; i<num_rows; i++)
00086     op1(i+1) = value;
00087 }
00088 
00089 // Number of Rows / Cols
00090 unsigned int MyColumnVector::rows() const { return this->size();}
00091 unsigned int MyColumnVector::columns() const { return 1;}
00092 unsigned int MyColumnVector::capacity() const { return this->size();}
00093 
00094 MyColumnVector
00095 MyColumnVector::vectorAdd(const MyColumnVector& v2) const
00096 {
00097   const MyColumnVector& v1 = *this;
00098   MyColumnVector res(v1.rows() + v2.rows());
00099 
00100   for (unsigned int i=0; i<v1.rows(); i++)
00101     res(i) = v1(i);
00102 
00103   for (unsigned int i=0; i<v2.rows(); i++)
00104     res(v1.rows()+i) = v2(i);
00105 
00106   return res;
00107 }
00108 
00109 const bool MyColumnVector::operator==(const MyColumnVector& a) const
00110 {
00111   const ltiColumnVector& op1 = *this;
00112   const ltiColumnVector& op2 = a;
00113   return (op1 == op2);
00114 }
00115 
00116 
00117 // Operators
00118 MyColumnVector & MyColumnVector::operator+= (const MyColumnVector& a)
00119 {
00120   ltiColumnVector & op1 = (*this);
00121   const ltiColumnVector & op2 = a;
00122   op1 += op2;
00123   return (MyColumnVector &) op1 ;
00124 }
00125 
00126 MyColumnVector & MyColumnVector::operator-= (const MyColumnVector& a)
00127 {
00128   ltiColumnVector & op1 = (*this);
00129   const ltiColumnVector & op2 = a;
00130   op1 -= op2;
00131   return (MyColumnVector &) op1 ;
00132 }
00133 
00134 MyColumnVector MyColumnVector::operator+ (const MyColumnVector &a) const
00135 {
00136   ltiColumnVector op1(*this);
00137   const ltiColumnVector & op2 = a;
00138   ltiColumnVector result = (ltiColumnVector) (op1.add(op2));
00139   return (MyColumnVector) result;
00140 }
00141 
00142 MyColumnVector MyColumnVector::operator- (const MyColumnVector &a) const
00143 {
00144   ltiColumnVector op1(*this);
00145   const ltiColumnVector & op2 = a;
00146   ltiColumnVector result = (ltiColumnVector) (op1.subtract(op2));
00147   return (MyColumnVector) result;
00148 }
00149 
00150 
00151 
00152 MyColumnVector& MyColumnVector::operator+= (double a)
00153 {
00154   ltiColumnVector& op1 = *this;
00155   op1 += a;
00156   return (MyColumnVector&) op1;
00157 }
00158 
00159 MyColumnVector& MyColumnVector::operator-= (double a)
00160 {
00161   ltiColumnVector& op1 = *this;
00162   op1 -= a;
00163   return (MyColumnVector&) op1;
00164 }
00165 
00166 
00167 MyColumnVector& MyColumnVector::operator*= (double a)
00168 {
00169   ltiColumnVector& op1 = *this;
00170   op1 *= a;
00171   return (MyColumnVector&) op1;
00172 }
00173 
00174 MyColumnVector& MyColumnVector::operator/= (double a)
00175 {
00176   ltiColumnVector& op1 = *this;
00177   op1 /= a;
00178   return (MyColumnVector&) op1;
00179 }
00180 
00181 
00182 MyColumnVector MyColumnVector::operator+ (double a) const
00183 {
00184   ltiColumnVector op1(*this);
00185   op1 += a;
00186   return (MyColumnVector&) op1;
00187 }
00188 
00189 
00190 MyColumnVector MyColumnVector::operator- (double a) const
00191 {
00192   ltiColumnVector op1(*this);
00193   op1 -= a;
00194   return (MyColumnVector&) op1;
00195 }
00196 
00197 MyColumnVector MyColumnVector::operator* (double a) const
00198 {
00199   ltiColumnVector op1(*this);
00200   return (MyColumnVector) (op1.multiply(a));
00201 }
00202 
00203 
00204 MyColumnVector MyColumnVector::operator/ (double a) const
00205 {
00206   ltiColumnVector op1(*this);
00207   return (MyColumnVector) (op1.divide(a));
00208 }
00209 
00210 
00211 
00212 
00213 
00214 
00215 
00216 MyRowVector MyColumnVector::transpose() const
00217 {
00218   ltiRowVector transposedbase((*this));
00219   return (MyRowVector) transposedbase;
00220 }
00221 
00222 MyMatrix MyColumnVector::operator* (const MyRowVector &a) const
00223 {
00224   const ltiColumnVector& op1 = *this;
00225   const ltiRowVector & op2 = a;
00226   ltiMatrix result(op1.size(),op2.size());
00227   result.outerProduct(op1,op2);
00228   return (MyMatrix) result;
00229 }
00230 
00231 MyColumnVector& MyColumnVector::operator=(const MyColumnVector &a)
00232 {
00233   // Both these implementations result in the same
00234   ltiColumnVector * op1; const ltiColumnVector * op2;
00235   op1 = this; op2 = &a;
00236   *op1 = *op2;
00237 
00238   return *this;
00239 }
00240 
00241 MyColumnVector& MyColumnVector::operator=(const double a)
00242 {
00243   // Both these implementations result in the same
00244   ltiColumnVector * op1;
00245   op1 = this;
00246   (*op1).fill(a,0,(*op1).size());
00247 
00248   return *this;
00249 }
00250 
00251 double &MyColumnVector::operator()(unsigned int i)
00252 {
00253   assert (i != 0);
00254   //ltiColumnVector * op1;
00255   //op1 = this;
00256   return this->at(i-1);
00257 }
00258 
00259 const double MyColumnVector::operator()(unsigned int i) const
00260 {
00261   assert (i != 0);
00262   //ltiColumnVector op1(*this);
00263   return this->at(i-1);
00264 }
00265 
00266 
00267 MyColumnVector MyColumnVector::sub(int j_start , int j_end) const
00268 {
00269   ltiColumnVector result(*this,j_start-1,j_end-1);
00270   return (MyColumnVector) result;
00271 }
00272 
00276 
00277 // Constructors
00278 MyRowVector::RowVector() : ltiRowVector() {}
00279 MyRowVector::RowVector(int num_rows) : ltiRowVector(num_rows){}
00280 
00281 // Destructor
00282 MyRowVector::~RowVector(){}
00283 
00284 // Copy constructor
00285 MyRowVector::RowVector(const MyRowVector& a) : ltiRowVector(a){}
00286 MyRowVector::RowVector(const ltiRowVector & a) : ltiRowVector(a){}
00287 
00288 // Number of Rows / Cols
00289 unsigned int MyRowVector::rows() const { return 1;}
00290 unsigned int MyRowVector::columns() const { return this->size();}
00291 unsigned int MyRowVector::capacity() const { return this->size();}
00292 
00293 const bool MyRowVector::operator==(const MyRowVector& a) const
00294 {
00295   const ltiRowVector& op1 = *this;
00296   const ltiRowVector& op2 = a;
00297   return (op1 == op2);
00298 }
00299 
00300 
00301 // Operators
00302 MyRowVector & MyRowVector::operator+= (const MyRowVector& a)
00303 {
00304   ltiRowVector & op1 = (*this);
00305   const ltiRowVector & op2 = a;
00306   op1 += op2;
00307   return (MyRowVector &) op1 ;
00308 }
00309 
00310 MyRowVector & MyRowVector::operator-= (const MyRowVector& a)
00311 {
00312   ltiRowVector & op1 = (*this);
00313   const ltiRowVector & op2 = a;
00314   op1 -= op2;
00315   return (MyRowVector &) op1 ;
00316 }
00317 
00318 MyRowVector MyRowVector::operator+ (const MyRowVector &a) const
00319 {
00320   ltiRowVector op1(*this);
00321   const ltiRowVector & op2 = a;
00322   ltiRowVector result = (ltiRowVector) (op1.add(op2));
00323   return (MyRowVector) result;
00324 }
00325 
00326 MyRowVector MyRowVector::operator- (const MyRowVector &a) const
00327 {
00328   ltiRowVector op1(*this);
00329   const ltiRowVector & op2 = a;
00330   ltiRowVector result = (ltiRowVector) (op1.subtract(op2));
00331   return (MyRowVector) result;
00332 }
00333 
00334 
00335 
00336 
00337 
00338 
00339 MyRowVector& MyRowVector::operator+= (double a)
00340 {
00341   ltiRowVector& op1 = *this;
00342   op1 += a;
00343   return (MyRowVector&) op1;
00344 }
00345 
00346 MyRowVector& MyRowVector::operator-= (double a)
00347 {
00348   ltiRowVector& op1 = *this;
00349   op1 -= a;
00350   return (MyRowVector&) op1;
00351 }
00352 
00353 
00354 MyRowVector& MyRowVector::operator*= (double a)
00355 {
00356   ltiRowVector& op1 = *this;
00357   op1 *= a;
00358   return (MyRowVector&) op1;
00359 }
00360 
00361 MyRowVector& MyRowVector::operator/= (double a)
00362 {
00363   ltiRowVector& op1 = *this;
00364   op1 /= a;
00365   return (MyRowVector&) op1;
00366 }
00367 
00368 
00369 MyRowVector MyRowVector::operator+ (double a) const
00370 {
00371   ltiRowVector op1(*this);
00372   op1 += a;
00373   return (MyRowVector&) op1;
00374 }
00375 
00376 
00377 MyRowVector MyRowVector::operator- (double a) const
00378 {
00379   ltiRowVector op1(*this);
00380   op1 -= a;
00381   return (MyRowVector&) op1;
00382 }
00383 
00384 MyRowVector MyRowVector::operator* (double a) const
00385 {
00386   ltiRowVector op1(*this);
00387   return (MyRowVector) (op1.multiply(a));
00388 }
00389 
00390 
00391 MyRowVector MyRowVector::operator/ (double a) const
00392 {
00393   ltiRowVector op1(*this);
00394   return (MyRowVector) (op1.divide(a));
00395 }
00396 
00397 MyRowVector MyRowVector::operator*(const MyMatrix& a)
00398 {
00399   assert(this->columns() == a.rows());
00400 
00401   ltiRowVector & op1 = (*this);
00402   const ltiMatrix & op2 = a;
00403   ltiRowVector result = op2.leftMultiply(op1);
00404   return (MyRowVector) result;
00405 }
00406 
00407 
00408 double MyRowVector::operator*(const MyColumnVector& a) const
00409 {
00410   assert(this->columns() == a.rows());
00411 
00412   const ltiRowVector & op1 = (*this);
00413   const ltiColumnVector & op2 = a;
00414   double result=op1.dot(op2);
00415   return result;
00416 }
00417 
00418 MyRowVector& MyRowVector::operator=(const MyRowVector &a)
00419 {
00420   // Both these implementations result in the same
00421   ltiRowVector * op1;
00422   const ltiRowVector * op2;
00423   op1 = this;
00424   op2 = &a;
00425   *op1 = *op2;
00426 
00427   return *this;
00428 }
00429 
00430 
00431 MyRowVector& MyRowVector::operator=(const double a)
00432 {
00433   // Both these implementations result in the same
00434   ltiRowVector * op1;
00435   op1 = this;
00436   (*op1).fill(a,0,(*op1).size());
00437 
00438   return *this;
00439 }
00440 
00441 
00442 MyColumnVector MyRowVector::transpose() const
00443 {
00444   ltiColumnVector transposedbase((*this));
00445   return (MyColumnVector) transposedbase;
00446 }
00447 
00448 
00449 double &MyRowVector::operator()(unsigned int i)
00450 {
00451   assert (i != 0);
00452   ltiRowVector * op1;
00453   op1 = this;
00454   return op1->at(i-1);
00455 }
00456 
00457 const double MyRowVector::operator()(unsigned int i) const
00458 {
00459   assert (i != 0);
00460   ltiRowVector op1(*this);
00461   return ((op1.at(i-1)));
00462 }
00463 
00464 
00465 
00466 MyRowVector MyRowVector::sub(int j_start , int j_end) const
00467 {
00468   ltiRowVector result(*this,j_start-1,j_end-1);
00469   return (MyRowVector) result;
00470 }
00471 
00472 // Resizing
00473 void MyRowVector::resize(int num_cols)
00474 {
00475   ltiRowVector & op1 = (*this);
00476   op1.resize(num_cols);
00477 }
00478 
00479 // Assign
00480 void MyRowVector::assign(int num_columns, double value)
00481 {
00482   ltiRowVector & op1 = (*this);
00483   op1.resize(num_columns);
00484   for (unsigned int i=0; i<num_columns; i++)
00485     op1(i+1) = value;
00486 }
00487 
00488 
00489 MyRowVector
00490 MyRowVector::vectorAdd(const MyRowVector& v2) const
00491 {
00492   const MyRowVector& v1 = *this;
00493   MyRowVector res(v1.columns() + v2.columns());
00494 
00495   for (unsigned int i=0; i<v1.columns(); i++)
00496     res(i) = v1(i);
00497 
00498   for (unsigned int i=0; i<v2.columns(); i++)
00499     res(v1.columns()+i) = v2(i);
00500 
00501   return res;
00502 }
00503 
00504 #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 Mon Feb 11 2019 03:45:12