DACE 2.0 API Manual
Differential Algebra Core Engine
AlgebraicVector_t.h
Go to the documentation of this file.
1 /******************************************************************************
2 * *
3 * DIFFERENTIAL ALGEBRA CORE ENGINE *
4 * *
5 *******************************************************************************
6 * *
7 * Copyright 2016 Politecnico di Milano (2014 Dinamica Srl) *
8 * Licensed under the Apache License, Version 2.0 (the "License"); *
9 * you may not use this file except in compliance with the License. *
10 * You may obtain a copy of the License at *
11 * *
12 * http://www.apache.org/licenses/LICENSE-2.0 *
13 * *
14 * Unless required by applicable law or agreed to in writing, software *
15 * distributed under the License is distributed on an "AS IS" BASIS, *
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
17 * See the License for the specific language governing permissions and *
18 * limitations under the License. *
19 * *
20 *******************************************************************************/
21 
22 /*
23  * AlgebraicVector_t.h
24  *
25  * Created on: Sep. 10, 2014
26  * Author: Dinamica Srl
27  */
28 
29 #ifndef DINAMICA_ALGEBRAICVECTOR_T_H_
30 #define DINAMICA_ALGEBRAICVECTOR_T_H_
31 
32 // C++ stdlib classes used only internally in this implementation
33 #include <cmath>
34 #include <sstream>
35 #include <stdexcept>
36 #include <string>
37 
38 // DACE classes
39 #include "dace/PromotionTrait.h"
40 #include "dace/MathExtension.h"
41 #include "dace/compiledDA.h"
42 #include "dace/AlgebraicVector.h"
43 #ifdef WITH_ALGEBRAICMATRIX
44 #include "dace/AlgebraicMatrix.h"
45 #include "dace/AlgebraicMatrix_t.h"
46 #endif /* WITH_ALGEBRAICMATRIX */
47 
48 namespace DACE{
49 
50 /***********************************************************************************
51 * Constructors
52 ************************************************************************************/
53 template<typename T> AlgebraicVector<T>::AlgebraicVector() : std::vector<T>(){
56 }
57 
58 template<typename T> AlgebraicVector<T>::AlgebraicVector(size_t size) : std::vector<T>(size){
62 }
63 
64 template<typename T> AlgebraicVector<T>::AlgebraicVector(size_t size, const T &d) : std::vector<T>(size, d){
69 }
70 
71 template<typename T> AlgebraicVector<T>::AlgebraicVector(const std::vector<T> &v) : std::vector<T>(v){
75 }
76 
77 template<typename T> AlgebraicVector<T>::AlgebraicVector(std::initializer_list<T> l) : std::vector<T>(l){
81 }
82 
83 template<typename T> AlgebraicVector<T>::AlgebraicVector(const std::vector<T> &v, size_t first, size_t last) : std::vector<T>(v.begin()+first, v.begin()+last+1){
91  // Notice that the range in the std::vector constructor above includes all
92  // elements between first and last, including the first excluding the last.
93  // Hence the +1.
94 }
95 
96 /***********************************************************************************
97 * Coefficient access routines
98 ************************************************************************************/
105  using DACE::cons;
106 
107  const size_t size = this->size();
108  AlgebraicVector<double> temp(size);
109  for(size_t i=0; i<size; i++){
110  temp[i] = cons((*this)[i]);}
111 
112  return temp;
113 }
114 
115 template<typename T> AlgebraicVector<T> AlgebraicVector<T>::extract(const size_t first, const size_t last) const
116 {
124  if(first>=this->size() || last>=this->size())
125  throw std::runtime_error("DACE::AlgebraicVector<T>::take: Indices out of bounds.");
126 
127  return AlgebraicVector<T>(*this, first, last);
128 }
129 
130 template<typename T> template<typename V> AlgebraicVector<typename PromotionTrait< T, V >::returnType> AlgebraicVector<T>::concat(const std::vector<V> &obj) const{
136  const size_t size1 = this->size();
137  const size_t size2 = obj.size();
139 
140  for(size_t i=0; i<size1; i++)
141  res[i] = (*this)[i];
142  for(size_t i=0; i<size2; i++)
143  res[i+size1] = obj[i];
144 
145  return res;
146 }
147 
148 /***********************************************************************************
149 * Algebraic operations
150 ************************************************************************************/
155  return -1.0*(*this);
156 }
157 
158 template<typename T> template<typename U> AlgebraicVector<T>& AlgebraicVector<T>::operator+=(const AlgebraicVector<U> &obj){
164  const size_t size = this->size();
165  if(size != obj.size())
166  throw std::runtime_error("DACE::AlgebraicVector<T>::operator+=: Vectors must have the same length.");
167 
168  for(size_t i=0; i<size; i++){
169  (*this)[i] += obj[i];}
170  return *this;
171 }
172 
173 template<typename T> template<typename U> AlgebraicVector<T>& AlgebraicVector<T>::operator+=(const U &obj){
178  const size_t size = this->size();
179  for(size_t i=0; i<size; i++){
180  (*this)[i] += obj;}
181  return *this;
182 }
183 
184 template<typename T> template<typename U> AlgebraicVector<T>& AlgebraicVector<T>::operator-=(const AlgebraicVector<U> &obj){
190  const size_t size = this->size();
191  if(size != obj.size())
192  throw std::runtime_error("DACE::AlgebraicVector<T>::operator-=: Vectors must have the same length.");
193 
194  for(size_t i=0; i<size; i++){
195  (*this)[i] -= obj[i];}
196  return *this;
197 }
198 
199 template<typename T> template<typename U> AlgebraicVector<T>& AlgebraicVector<T>::operator-=(const U &obj){
204  const size_t size = this->size();
205  for(size_t i=0; i<size; i++){
206  (*this)[i] -= obj;}
207  return *this;
208 }
209 
210 template<typename T> template<typename U> AlgebraicVector<T>& AlgebraicVector<T>::operator*=(const AlgebraicVector<U> &obj){
215  const size_t size = this->size();
216  if(size != obj.size())
217  throw std::runtime_error("DACE::AlgebraicVector<T>::operator*=: Vectors must have the same length.");
218 
219  for(size_t i=0; i<size; i++){
220  (*this)[i] *= obj[i];}
221  return *this;
222 }
223 
224 template<typename T> template<typename U> AlgebraicVector<T>& AlgebraicVector<T>::operator*=(const U &obj){
229  const size_t size = this->size();
230  for(size_t i=0; i<size; i++){
231  (*this)[i] *= obj;}
232  return *this;
233 }
234 
235 template<typename T> template<typename U> AlgebraicVector<T>& AlgebraicVector<T>::operator/=(const AlgebraicVector<U> &obj){
241  const size_t size = this->size();
242  if(size != obj.size())
243  throw std::runtime_error("DACE::AlgebraicVector<T>::operator/=: Vectors must have the same length.");
244 
245  for(size_t i=0; i<size; i++){
246  (*this)[i] /= obj[i];}
247  return *this;
248 }
249 
250 template<typename T> template<typename U> AlgebraicVector<T>& AlgebraicVector<T>::operator/=(const U &obj){
255  const size_t size = this->size();
256  for(size_t i=0; i<size; i++){
257  (*this)[i] /= obj;}
258  return *this;
259 }
260 
261 template<typename T> template<typename U> AlgebraicVector<T>& AlgebraicVector<T>::operator<<(const std::vector<U> &obj){
266  const size_t size = obj.size();
267  for(size_t i=0; i<size; i++){
268  (*this).push_back((T)obj[i]);}
269  return *this;
270 }
271 
279  if(obj1.size() != obj2.size())
280  throw std::runtime_error("DACE::AlgebraicVector<T>::operator+: Vectors must have the same length.");
281 
282  const size_t size = obj1.size();
284  for(size_t i=0; i<size; i++){
285  temp[i] = obj1[i] + obj2[i];}
286  return temp;
287 }
288 
289 template<typename U,typename V> AlgebraicVector<typename PromotionTrait< U, V >::returnType> operator+(const AlgebraicVector<U> &obj1, const V &obj2){
295  const size_t size = obj1.size();
297  for(size_t i=0; i<size; i++){
298  temp[i] = obj1[i] + obj2;}
299  return temp;
300 }
301 
302 template<typename U,typename V> AlgebraicVector<typename PromotionTrait< U, V >::returnType> operator+(const U &obj1, const AlgebraicVector<V> &obj2){
308  const size_t size = obj2.size();
310  for(size_t i=0; i<size; i++){
311  temp[i] = obj1 + obj2[i];}
312  return temp;
313 }
314 
322  if(obj1.size() != obj2.size())
323  throw std::runtime_error("DACE::AlgebraicVector<T>::operator-: Vectors must have the same length.");
324 
325  const size_t size = obj1.size();
327  for(size_t i=0; i<size; i++){
328  temp[i] = obj1[i] - obj2[i];}
329  return temp;
330 }
331 
332 template<typename U,typename V> AlgebraicVector<typename PromotionTrait< U, V >::returnType> operator-(const AlgebraicVector<U> &obj1, const V &obj2){
338  const size_t size = obj1.size();
340  for(size_t i=0; i<size; i++){
341  temp[i] = obj1[i] - obj2;}
342  return temp;
343 }
344 
345 template<typename U,typename V> AlgebraicVector<typename PromotionTrait< U, V >::returnType> operator-(const U &obj1, const AlgebraicVector<V> &obj2){
351  const size_t size = obj2.size();
353  for(size_t i=0; i<size; i++){
354  temp[i] = obj1 - obj2[i];}
355  return temp;
356 }
357 
365  if(obj1.size() != obj2.size())
366  throw std::runtime_error("DACE::AlgebraicVector<T>::operator*: Vectors must have the same length.");
367 
368  const size_t size = obj1.size();
370  for(size_t i=0; i<size; i++){
371  temp[i] = obj1[i] * obj2[i];}
372  return temp;
373 }
374 
375 template<typename U,typename V> AlgebraicVector<typename PromotionTrait< U, V >::returnType> operator*(const AlgebraicVector<U> &obj1, const V &obj2){
381  const size_t size = obj1.size();
383  for(size_t i=0; i<size; i++){
384  temp[i] = obj1[i] * obj2;}
385  return temp;
386 }
387 
388 template<typename U,typename V> AlgebraicVector<typename PromotionTrait< U, V >::returnType> operator*(const U &obj1, const AlgebraicVector<V> &obj2){
394  const size_t size = obj2.size();
396  for(size_t i=0; i<size; i++){
397  temp[i] = obj1 * obj2[i];}
398  return temp;
399 }
400 
408  if(obj1.size() != obj2.size())
409  throw std::runtime_error("DACE::AlgebraicVector<T>::operator/: Vectors must have the same length.");
410 
411  const size_t size = obj1.size();
413  for(size_t i=0; i<size; i++){
414  temp[i] = obj1[i] / obj2[i];}
415  return temp;
416 }
417 
418 template<typename U,typename V> AlgebraicVector<typename PromotionTrait< U, V >::returnType> operator/(const AlgebraicVector<U> &obj1, const V &obj2){
424  const size_t size = obj1.size();
426  for(size_t i=0; i<size; i++){
427  temp[i] = obj1[i] / obj2;}
428  return temp;
429 }
430 
431 template<typename U,typename V> AlgebraicVector<typename PromotionTrait< U, V >::returnType> operator/(const U &obj1, const AlgebraicVector<V> &obj2){
437  const size_t size = obj2.size();
439  for(size_t i=0; i<size; i++){
440  temp[i] = obj1 / obj2[i];}
441  return temp;
442 }
443 
444 template<typename T> template<typename V> typename PromotionTrait<T,V>::returnType AlgebraicVector<T>::dot(const AlgebraicVector<V> &obj) const{
450  const size_t size = this->size();
451  if(size != obj.size())
452  throw std::runtime_error("DACE::AlgebraicVector<T>::dot(): Vectors must have the same length.");
453 
454  typename PromotionTrait<T,V>::returnType temp = 0;
455  for(size_t i=0; i<size; i++){
456  temp += (*this)[i] * obj[i];}
457 
458  return temp;
459 }
460 
467  if((this->size() != 3) || (obj.size() != 3))
468  throw std::runtime_error("DACE::AlgebraicVector<T>::cross(): Inputs must be 3 element AlgebraicVectors.");
469 
471 
472  temp[0] = ((*this)[1] * obj[2]) - ((*this)[2] * obj[1]);
473  temp[1] = ((*this)[2] * obj[0]) - ((*this)[0] * obj[2]);
474  temp[2] = ((*this)[0] * obj[1]) - ((*this)[1] * obj[0]);
475 
476  return temp;
477 }
478 
479 /***********************************************************************************
480 * Math routines
481 ************************************************************************************/
482 template<typename T> AlgebraicVector<T> AlgebraicVector<T>::pow(const int p) const{
488  using std::pow;
489 
490  const size_t size = this->size();
491  AlgebraicVector<T> temp(size);
492  for(size_t i=0; i<size; i++){
493  temp[i] = pow((*this)[i], p);}
494 
495  return temp;
496 }
497 
498 template<typename T> AlgebraicVector<T> AlgebraicVector<T>::sqrt() const{
503  using std::sqrt;
504 
505  const size_t size = this->size();
506  AlgebraicVector<T> temp(size);
507  for(size_t i=0; i<size; i++){
508  temp[i] = sqrt((*this)[i]);}
509 
510  return temp;
511 }
512 
513 template<typename T> AlgebraicVector<T> AlgebraicVector<T>::exp() const{
518  using std::exp;
519 
520  const size_t size = this->size();
521  AlgebraicVector<T> temp(size);
522  for(size_t i=0; i<size; i++){
523  temp[i] = exp((*this)[i]);}
524 
525  return temp;
526 }
527 
528 template<typename T> AlgebraicVector<T> AlgebraicVector<T>::log() const{
533  using std::log;
534 
535  const size_t size = this->size();
536  AlgebraicVector<T> temp(size);
537  for(size_t i=0; i<size; i++){
538  temp[i] = log((*this)[i]);}
539 
540  return temp;
541 }
542 
543 template<typename T> AlgebraicVector<T> AlgebraicVector<T>::sin() const{
548  using std::sin;
549 
550  const size_t size = this->size();
551  AlgebraicVector<T> temp(size);
552  for(size_t i=0; i<size; i++){
553  temp[i] = sin((*this)[i]);}
554 
555  return temp;
556 }
557 
558 template<typename T> AlgebraicVector<T> AlgebraicVector<T>::cos() const{
563  using std::cos;
564 
565  const size_t size = this->size();
566  AlgebraicVector<T> temp(size);
567  for(size_t i=0; i<size; i++){
568  temp[i] = cos((*this)[i]);}
569 
570  return temp;
571 }
572 
573 template<typename T> AlgebraicVector<T> AlgebraicVector<T>::tan() const{
578  using std::tan;
579 
580  const size_t size = this->size();
581  AlgebraicVector<T> temp(size);
582  for(size_t i=0; i<size; i++){
583  temp[i] = tan((*this)[i]);}
584 
585  return temp;
586 }
587 
588 template<typename T> AlgebraicVector<T> AlgebraicVector<T>::asin() const{
593  using std::asin;
594 
595  const size_t size = this->size();
596  AlgebraicVector<T> temp(size);
597  for(size_t i=0; i<size; i++){
598  temp[i] = asin((*this)[i]);}
599 
600  return temp;
601 }
602 
603 template<typename T> AlgebraicVector<T> AlgebraicVector<T>::acos() const{
608  using std::acos;
609 
610  const size_t size = this->size();
611  AlgebraicVector<T> temp(size);
612  for(size_t i=0; i<size; i++){
613  temp[i] = acos((*this)[i]);}
614 
615  return temp;
616 }
617 
618 template<typename T> AlgebraicVector<T> AlgebraicVector<T>::atan() const{
623  using std::atan;
624 
625  const size_t size = this->size();
626  AlgebraicVector<T> temp(size);
627  for(size_t i=0; i<size; i++){
628  temp[i] = atan((*this)[i]);}
629 
630  return temp;
631 }
632 
633 template<typename T> AlgebraicVector<T> AlgebraicVector<T>::atan2(const AlgebraicVector<T> &obj) const{
641  using std::atan2;
642 
643  const size_t size = this->size();
644  if(obj.size() != size)
645  throw std::runtime_error("DACE::AlgebraicVector<T>::atan2(): Vectors must have the same length.");
646 
647  AlgebraicVector<T> temp(size);
648  for(size_t i=0; i<size; i++){
649  temp[i] = atan2((*this)[i], obj[i]);}
650 
651  return temp;
652 }
653 
654 template<typename T> AlgebraicVector<T> AlgebraicVector<T>::sinh() const{
659  using std::sinh;
660 
661  const size_t size = this->size();
662  AlgebraicVector<T> temp(size);
663  for(size_t i=0; i<size; i++){
664  temp[i] = sinh((*this)[i]);}
665 
666  return temp;
667 }
668 
669 template<typename T> AlgebraicVector<T> AlgebraicVector<T>::cosh() const{
674  using std::cosh;
675 
676  const size_t size = this->size();
677  AlgebraicVector<T> temp(size);
678  for(size_t i=0; i<size; i++){
679  temp[i] = cosh((*this)[i]);}
680 
681  return temp;
682 }
683 
684 template<typename T> AlgebraicVector<T> AlgebraicVector<T>::tanh() const{
689  using std::tanh;
690 
691  const size_t size = this->size();
692  AlgebraicVector<T> temp(size);
693  for(size_t i=0; i<size; i++){
694  temp[i] = tanh((*this)[i]);}
695 
696  return temp;
697 }
698 
699 template<typename T> AlgebraicVector<T> AlgebraicVector<T>::logb(const double b) const{
705  using DACE::logb;
706 
707  const size_t size = this->size();
708  AlgebraicVector<T> temp(size);
709  for(size_t i=0; i<size; i++){
710  temp[i] = logb((*this)[i], b);}
711 
712  return temp;
713 }
714 
715 template<typename T> AlgebraicVector<T> AlgebraicVector<T>::isrt() const{
720  using DACE::isrt;
721 
722  const size_t size = this->size();
723  AlgebraicVector<T> temp(size);
724  for(size_t i=0; i<size; i++){
725  temp[i] = isrt((*this)[i]);}
726 
727  return temp;
728 }
729 
730 template<typename T> AlgebraicVector<T> AlgebraicVector<T>::sqr() const{
735  using DACE::sqr;
736 
737  const size_t size = this->size();
738  AlgebraicVector<T> temp(size);
739  for(size_t i=0; i<size; i++){
740  temp[i] = sqr((*this)[i]);}
741 
742  return temp;
743 }
744 
745 template<typename T> AlgebraicVector<T> AlgebraicVector<T>::minv() const{
750  using DACE::minv;
751 
752  const size_t size = this->size();
753  AlgebraicVector<T> temp(size);
754  for(size_t i=0; i<size; i++){
755  temp[i] = minv((*this)[i]);}
756 
757  return temp;
758 }
759 
760 template<typename T> AlgebraicVector<T> AlgebraicVector<T>::root(const int p) const{
766  using DACE::root;
767 
768  const size_t size = this->size();
769  AlgebraicVector<T> temp(size);
770  for(size_t i=0; i<size; i++){
771  temp[i] = root((*this)[i],p);}
772 
773  return temp;
774 }
775 
776 template<typename T> AlgebraicVector<T> AlgebraicVector<T>::asinh() const{
781  using DACE::asinh;
782 
783  const size_t size = this->size();
784  AlgebraicVector<T> temp(size);
785  for(size_t i=0; i<size; i++){
786  temp[i] = asinh((*this)[i]);}
787 
788  return temp;
789 }
790 
791 template<typename T> AlgebraicVector<T> AlgebraicVector<T>::acosh() const{
796  using DACE::acosh;
797 
798  const size_t size = this->size();
799  AlgebraicVector<T> temp(size);
800  for(size_t i=0; i<size; i++){
801  temp[i] = acosh((*this)[i]);}
802 
803  return temp;
804 }
805 
806 template<typename T> AlgebraicVector<T> AlgebraicVector<T>::atanh() const{
811  using DACE::atanh;
812 
813  const size_t size = this->size();
814  AlgebraicVector<T> temp(size);
815  for(size_t i=0; i<size; i++){
816  temp[i] = atanh((*this)[i]);}
817 
818  return temp;
819 }
820 
821 /***********************************************************************************
822 * Vector norm routines
823 ************************************************************************************/
824 template<typename T> T AlgebraicVector<T>::vnorm() const{
828  using std::sqrt; using DACE::sqr; // Implementational note: these using statements are very subtle and absolutely needed.
829  // They force the compiler to perform argument dependent lookup (ADL) which then finds
830  // the correct root() and pow() functions even if they are not in DACE:: or std::!
831  const size_t size = this->size();
832  T norm = 0.0;
833  for(size_t i=0; i<size; i++){
834  norm = norm + sqr((*this)[i]);}
835 
836  return sqrt(norm);
837 }
838 
843  const size_t size = this->size();
844  AlgebraicVector<T> temp(size);
845  T norm = 1.0/this->vnorm();
846 
847  for(size_t i=0; i<size; i++){
848  temp[i] = (*this)[i]*norm;}
849 
850  return temp;
851 }
852 
853 /***********************************************************************************
854 * Polynomial evaluation routines
855 ************************************************************************************/
856 template<> template<typename V> V AlgebraicVector<DA>::eval(const V &args) const{
867  return compiledDA(*this).eval(args);
868 }
869 
870 template<> template<typename U> AlgebraicVector<U> AlgebraicVector<DA>::eval(const std::initializer_list<U> l) const{
879  return compiledDA(*this).eval<U>(l);
880 }
881 
882 template<> template<typename U> AlgebraicVector<U> AlgebraicVector<DA>::evalScalar(const U &arg) const{
895  return compiledDA(*this).evalScalar(arg);
896 }
897 
898 /***********************************************************************************
899 * Input/Output routines
900 ************************************************************************************/
901 template<typename U> std::ostream& operator<<(std::ostream &out, const AlgebraicVector<U> &obj){
907  const size_t size = obj.size();
908 
909  out << "[[[ " << size << " vector" << std::endl;
910  for(size_t i=0; i<size;i++){
911  out << obj[i] << std::endl;}
912  out << "]]]" << std::endl;
913 
914  return out;
915 }
916 
917 template<typename U> std::istream& operator>>(std::istream &in, AlgebraicVector<U> &obj){
923  std::string init_line;
924  size_t vec_size;
925 
926  // try to read the first line
927  getline(in, init_line);
928  if(in.good()){
929  // retrieve the size of the vector to be read
930  std::size_t found = init_line.find_first_of(' ');
931  std::string size_str(init_line,4,found-4);
932  if(!(std::istringstream(size_str) >> vec_size)) vec_size = 0;
933 
934  // resize the object to meet the size of the vector to be read
935  obj.resize(vec_size);
936 
937  // fill the AlgebraicVector
938  for (size_t i = 0; in.good() && (i < vec_size); i++) {
939  in >> obj[i];
940 
941  // check the next character
942  if (in.peek() == '\n') // the previous operator>> does not consume the \n character when an AlgebraicVector<T> (with T != DA) is considered
943  in.ignore(); // ignore the next character
944  }
945  // skip the line at the end of a AlgebraicVector (containing ]]])
946  getline(in, init_line);
947  }else{
948  obj.resize(0);}
949 
950  return in;
951 }
952 
953 template<typename T> std::string AlgebraicVector<T>::toString() const{
957  std::ostringstream strs;
958  strs << *this << std::endl;
959 
960  return strs.str();
961 }
962 
963 /***********************************************************************************
964 * Non-member functions
965 ************************************************************************************/
966 template<typename T> AlgebraicVector<double> cons(const AlgebraicVector<T> &obj){
971  return obj.cons();
972 }
973 
974 template<typename T> AlgebraicVector<T> pow(const AlgebraicVector<T> &obj, const int p){
982  return obj.pow(p);
983 }
984 
985 template<typename T> AlgebraicVector<T> root(const AlgebraicVector<T> &obj, const int p){
993  return obj.root(p);
994 }
995 
996 template<typename T> AlgebraicVector<T> minv(const AlgebraicVector<T> &obj){
1003  return obj.minv();
1004 }
1005 
1006 template<typename T> AlgebraicVector<T> sqr(const AlgebraicVector<T> &obj){
1013  return obj.sqr();
1014 }
1015 
1016 template<typename T> AlgebraicVector<T> sqrt(const AlgebraicVector<T> &obj){
1023  return obj.sqrt();
1024 }
1025 
1026 template<typename T> AlgebraicVector<T> isrt(const AlgebraicVector<T> &obj){
1033  return obj.isrt();
1034 }
1035 
1036 template<typename T> AlgebraicVector<T> exp(const AlgebraicVector<T> &obj){
1043  return obj.exp();
1044 }
1045 
1046 template<typename T> AlgebraicVector<T> log(const AlgebraicVector<T> &obj){
1053  return obj.log();
1054 }
1055 
1056 template<typename T> AlgebraicVector<T> logb(const AlgebraicVector<T> &obj, const double b){
1064  return obj.logb(b);
1065 }
1066 
1067 template<typename T> AlgebraicVector<T> sin(const AlgebraicVector<T> &obj){
1074  return obj.sin();
1075 }
1076 
1077 template<typename T> AlgebraicVector<T> cos(const AlgebraicVector<T> &obj){
1084  return obj.cos();
1085 }
1086 
1087 template<typename T> AlgebraicVector<T> tan(const AlgebraicVector<T> &obj){
1094  return obj.tan();
1095 }
1096 
1097 template<typename T> AlgebraicVector<T> asin(const AlgebraicVector<T> &obj){
1104  return obj.asin();
1105 }
1106 
1107 template<typename T> AlgebraicVector<T> acos(const AlgebraicVector<T> &obj){
1114  return obj.acos();
1115 }
1116 
1117 template<typename T> AlgebraicVector<T> atan(const AlgebraicVector<T> &obj){
1124  return obj.atan();
1125 }
1126 
1127 template<typename T> AlgebraicVector<T> atan2(const AlgebraicVector<T> &obj1, const AlgebraicVector<T> &obj2){
1135  return obj1.atan(obj2);
1136 }
1137 
1138 template<typename T> AlgebraicVector<T> sinh(const AlgebraicVector<T> &obj){
1145  return obj.sinh();
1146 }
1147 
1148 template<typename T> AlgebraicVector<T> cosh(const AlgebraicVector<T> &obj){
1155  return obj.cosh();
1156 }
1157 
1158 template<typename T> AlgebraicVector<T> tanh(const AlgebraicVector<T> &obj){
1165  return obj.tanh();
1166 }
1167 
1168 template<typename T> AlgebraicVector<T> asinh(const AlgebraicVector<T> &obj){
1175  return obj.asinh();
1176 }
1177 
1178 template<typename T> AlgebraicVector<T> acosh(const AlgebraicVector<T> &obj){
1185  return obj.acosh();
1186 }
1187 
1188 template<typename T> AlgebraicVector<T> atanh(const AlgebraicVector<T> &obj){
1195  return obj.atanh();
1196 }
1197 
1198 template<typename U, typename V> typename PromotionTrait<U,V>::returnType dot(const AlgebraicVector<U> &obj1, const AlgebraicVector<V> &obj2){
1204  return obj1.dot(obj2);
1205 }
1206 
1213  return obj1.cross(obj2);
1214 }
1215 
1216 template<typename T> T vnorm(const AlgebraicVector<T> &obj){
1222  return obj.vnorm();
1223 }
1224 
1225 template<typename T> AlgebraicVector<T> normalize(const AlgebraicVector<T> &obj){
1231  return obj.normalize();
1232 }
1233 
1234 template<typename V> V eval(const AlgebraicVector<DA> &obj, const V &args){
1242  return obj.eval(args);
1243 }
1244 
1245 template<typename T> AlgebraicVector<T> eval(const AlgebraicVector<DA> &obj, const std::initializer_list<T> l){
1256  return obj.eval<T>(l);
1257 }
1258 
1259 template<typename U> AlgebraicVector<U> evalScalar(const AlgebraicVector<DA> &obj, const U &arg){
1267  return obj.evalScalar(arg);
1268 }
1269 
1270 }
1271 #endif /* DINAMICA_ALGEBRAICVECTOR_T_H_ */
T vnorm() const
Euclidean vector norm (length).
Definition: AlgebraicVector_t.h:824
AlgebraicVector< T > acosh() const
Element-wise hyperbolic arccosine.
Definition: AlgebraicVector_t.h:791
std::istream & operator>>(std::istream &in, AlgebraicMatrix< DA > &obj)
DA specialization of input stream operator.
Definition: AlgebraicMatrix.cpp:65
DA operator/(const DA &da1, const DA &da2)
Definition: DA.cpp:804
AlgebraicVector< double > cons() const
Return vector containing only the costant parts of each element.
Definition: AlgebraicVector_t.h:99
DA exp(const DA &da)
Definition: DA.cpp:2213
AlgebraicVector< T > atanh() const
Element-wise hyperbolic arctangent.
Definition: AlgebraicVector_t.h:806
AlgebraicVector< T > log() const
Element-wise natural logarithm.
Definition: AlgebraicVector_t.h:528
AlgebraicVector< U > evalScalar(const U &arg) const
Generic evaluation of a AlgebraicVector<DA> with single argument. DA only.
DA cos(const DA &da)
Definition: DA.cpp:2276
double norm(const DA &da, unsigned int type)
Definition: DA.cpp:2567
DA tan(const DA &da)
Definition: DA.cpp:2286
AlgebraicVector< T > acos() const
Element-wise arccosine.
Definition: AlgebraicVector_t.h:603
AlgebraicVector< typename PromotionTrait< T, U >::returnType > concat(const std::vector< U > &obj) const
Return a new vector containing the elements of this vector followed by those of obj.
AlgebraicVector< T > normalize() const
Normalized vector of unit length along this vector.
Definition: AlgebraicVector_t.h:839
DA logb(const DA &da, const double b)
Definition: DA.cpp:2233
double returnType
Definition: PromotionTrait.h:42
STL namespace.
AlgebraicVector< T > minv() const
Element-wise multiplicative inverse.
Definition: AlgebraicVector_t.h:745
DA log(const DA &da)
Definition: DA.cpp:2223
AlgebraicVector< T > isrt() const
Element-wise inverse square root.
Definition: AlgebraicVector_t.h:715
DA acos(const DA &da)
Definition: DA.cpp:2306
AlgebraicVector< T > & operator*=(const AlgebraicVector< U > &obj)
Definition: AlgebraicVector_t.h:210
DA operator*(const DA &da1, const DA &da2)
Definition: DA.cpp:759
AlgebraicVector< T > extract(const size_t first, const size_t last) const
Return the subvector containing the elements between first and last, inclusively. ...
Definition: AlgebraicVector_t.h:115
std::string toString() const
Convert the vector into a human readable string.
Definition: AlgebraicVector_t.h:953
double pow()
AlgebraicVector< T > & operator-=(const AlgebraicVector< U > &obj)
Definition: AlgebraicVector_t.h:184
DA atanh(const DA &da)
Definition: DA.cpp:2387
DA atan2(const DA &da1, const DA &da2)
Definition: DA.cpp:2326
PromotionTrait< T, V >::returnType dot(const AlgebraicVector< V > &obj) const
Dot product (scalar product, inner product) of two vectors.
Definition: AlgebraicVector_t.h:444
DA asinh(const DA &da)
Definition: DA.cpp:2367
DA isrt(const DA &da)
Definition: DA.cpp:2170
DA acosh(const DA &da)
Definition: DA.cpp:2377
Definition: compiledDA.h:41
AlgebraicVector< T > atan() const
Element-wise arctangent.
Definition: AlgebraicVector_t.h:618
AlgebraicVector< T > sinh() const
Element-wise hyperbolic sine.
Definition: AlgebraicVector_t.h:654
AlgebraicVector< T > atan2(const AlgebraicVector< T > &obj) const
Element-wise arctangent in [-pi, pi].
Definition: AlgebraicVector_t.h:633
AlgebraicVector< T > root(const int p=2) const
Element-wise p-th root.
Definition: AlgebraicVector_t.h:760
Definition: AlgebraicMatrix.h:43
DA sin(const DA &da)
Definition: DA.cpp:2266
AlgebraicVector< T > asin() const
Element-wise arcsine.
Definition: AlgebraicVector_t.h:588
AlgebraicVector< T > tan() const
Element-wise tangent.
Definition: AlgebraicVector_t.h:573
AlgebraicVector< T > exp() const
Element-wise exponential.
Definition: AlgebraicVector_t.h:513
DA asin(const DA &da)
Definition: DA.cpp:2296
DA tanh(const DA &da)
Definition: DA.cpp:2357
V eval(const V &args) const
Generic evaluation of a AlgebraicVector<DA> with arguments. DA only.
AlgebraicVector< T > cos() const
Element-wise cosine.
Definition: AlgebraicVector_t.h:558
AlgebraicVector< T > cosh() const
Element-wise hyperbolic cosine.
Definition: AlgebraicVector_t.h:669
AlgebraicVector< T > sqrt() const
Element-wise square root.
Definition: AlgebraicVector_t.h:498
AlgebraicVector< typename PromotionTrait< T, V >::returnType > cross(const AlgebraicVector< V > &obj) const
Cross product of two vectors of length 3.
Definition: AlgebraicVector_t.h:461
AlgebraicVector< T > tanh() const
Element-wise hyperbolic tangent.
Definition: AlgebraicVector_t.h:684
AlgebraicVector< T > sin() const
Element-wise sine.
Definition: AlgebraicVector_t.h:543
AlgebraicVector< T > & operator/=(const AlgebraicVector< U > &obj)
Definition: AlgebraicVector_t.h:235
DA atan(const DA &da)
Definition: DA.cpp:2316
DA sqr(const DA &da)
Definition: DA.cpp:2150
Definition: AlgebraicMatrix.cpp:39
double cons(const DA &da)
Definition: DA.cpp:1970
AlgebraicVector< T > pow(const int p) const
Element-wise exponentiation to (integer) power.
Definition: AlgebraicVector_t.h:482
AlgebraicVector< T > & operator<<(const std::vector< U > &obj)
Concatenation operator.
Definition: AlgebraicVector_t.h:261
AlgebraicVector< T > operator-() const
Definition: AlgebraicVector_t.h:151
AlgebraicVector< T > & operator+=(const AlgebraicVector< U > &obj)
Definition: AlgebraicVector_t.h:158
unsigned int size(const DA &da)
Definition: DA.cpp:2549
DA minv(const DA &da)
Definition: DA.cpp:2140
DA sqrt(const DA &da)
Definition: DA.cpp:2160
AlgebraicVector< T > asinh() const
Element-wise hyperbolic arcsine.
Definition: AlgebraicVector_t.h:776
std::vector< T > evalScalar(const T &arg) const
Evaluate the compiled polynomial with a single variable of arithmetic type and return vector of resul...
Definition: compiledDA_t.h:94
DA root(const DA &da, int p)
Definition: DA.cpp:2129
DA sinh(const DA &da)
Definition: DA.cpp:2337
AlgebraicVector()
Default constructor.
Definition: AlgebraicVector_t.h:53
AlgebraicVector< T > sqr() const
Element-wise square.
Definition: AlgebraicVector_t.h:730
V eval(const V &args) const
Evaluate the compiled polynomial with a vector of any arithmetic type and return vector of results...
Definition: compiledDA_t.h:40
DA cosh(const DA &da)
Definition: DA.cpp:2347
DA operator+(const DA &da1, const DA &da2)
Definition: DA.cpp:669
AlgebraicVector< T > logb(const double b=10.0) const
Element-wise logarithm wrt a given base.
Definition: AlgebraicVector_t.h:699