29 #ifndef DINAMICA_ALGEBRAICVECTOR_T_H_ 30 #define DINAMICA_ALGEBRAICVECTOR_T_H_ 43 #ifdef WITH_ALGEBRAICMATRIX 109 for(
size_t i=0; i<
size; i++){
110 temp[i] =
cons((*
this)[i]);}
124 if(first>=this->
size() || last>=this->
size())
125 throw std::runtime_error(
"DACE::AlgebraicVector<T>::take: Indices out of bounds.");
136 const size_t size1 = this->
size();
137 const size_t size2 = obj.size();
140 for(
size_t i=0; i<size1; i++)
142 for(
size_t i=0; i<size2; i++)
143 res[i+size1] = obj[i];
165 if(size != obj.size())
166 throw std::runtime_error(
"DACE::AlgebraicVector<T>::operator+=: Vectors must have the same length.");
168 for(
size_t i=0; i<
size; i++){
169 (*this)[i] += obj[i];}
179 for(
size_t i=0; i<
size; i++){
191 if(size != obj.size())
192 throw std::runtime_error(
"DACE::AlgebraicVector<T>::operator-=: Vectors must have the same length.");
194 for(
size_t i=0; i<
size; i++){
195 (*this)[i] -= obj[i];}
205 for(
size_t i=0; i<
size; i++){
216 if(size != obj.size())
217 throw std::runtime_error(
"DACE::AlgebraicVector<T>::operator*=: Vectors must have the same length.");
219 for(
size_t i=0; i<
size; i++){
220 (*this)[i] *= obj[i];}
230 for(
size_t i=0; i<
size; i++){
242 if(size != obj.size())
243 throw std::runtime_error(
"DACE::AlgebraicVector<T>::operator/=: Vectors must have the same length.");
245 for(
size_t i=0; i<
size; i++){
246 (*this)[i] /= obj[i];}
256 for(
size_t i=0; i<
size; i++){
266 const size_t size = obj.size();
267 for(
size_t i=0; i<
size; i++){
268 (*this).push_back((T)obj[i]);}
279 if(obj1.size() != obj2.size())
280 throw std::runtime_error(
"DACE::AlgebraicVector<T>::operator+: Vectors must have the same length.");
282 const size_t size = obj1.size();
284 for(
size_t i=0; i<
size; i++){
285 temp[i] = obj1[i] + obj2[i];}
295 const size_t size = obj1.size();
297 for(
size_t i=0; i<
size; i++){
298 temp[i] = obj1[i] + obj2;}
308 const size_t size = obj2.size();
310 for(
size_t i=0; i<
size; i++){
311 temp[i] = obj1 + obj2[i];}
322 if(obj1.size() != obj2.size())
323 throw std::runtime_error(
"DACE::AlgebraicVector<T>::operator-: Vectors must have the same length.");
325 const size_t size = obj1.size();
327 for(
size_t i=0; i<
size; i++){
328 temp[i] = obj1[i] - obj2[i];}
338 const size_t size = obj1.size();
340 for(
size_t i=0; i<
size; i++){
341 temp[i] = obj1[i] - obj2;}
351 const size_t size = obj2.size();
353 for(
size_t i=0; i<
size; i++){
354 temp[i] = obj1 - obj2[i];}
365 if(obj1.size() != obj2.size())
366 throw std::runtime_error(
"DACE::AlgebraicVector<T>::operator*: Vectors must have the same length.");
368 const size_t size = obj1.size();
370 for(
size_t i=0; i<
size; i++){
371 temp[i] = obj1[i] * obj2[i];}
381 const size_t size = obj1.size();
383 for(
size_t i=0; i<
size; i++){
384 temp[i] = obj1[i] * obj2;}
394 const size_t size = obj2.size();
396 for(
size_t i=0; i<
size; i++){
397 temp[i] = obj1 * obj2[i];}
408 if(obj1.size() != obj2.size())
409 throw std::runtime_error(
"DACE::AlgebraicVector<T>::operator/: Vectors must have the same length.");
411 const size_t size = obj1.size();
413 for(
size_t i=0; i<
size; i++){
414 temp[i] = obj1[i] / obj2[i];}
424 const size_t size = obj1.size();
426 for(
size_t i=0; i<
size; i++){
427 temp[i] = obj1[i] / obj2;}
437 const size_t size = obj2.size();
439 for(
size_t i=0; i<
size; i++){
440 temp[i] = obj1 / obj2[i];}
451 if(size != obj.size())
452 throw std::runtime_error(
"DACE::AlgebraicVector<T>::dot(): Vectors must have the same length.");
455 for(
size_t i=0; i<
size; i++){
456 temp += (*this)[i] * obj[i];}
467 if((this->
size() != 3) || (obj.size() != 3))
468 throw std::runtime_error(
"DACE::AlgebraicVector<T>::cross(): Inputs must be 3 element AlgebraicVectors.");
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]);
492 for(
size_t i=0; i<
size; i++){
493 temp[i] =
pow((*
this)[i], p);}
507 for(
size_t i=0; i<
size; i++){
508 temp[i] =
sqrt((*
this)[i]);}
522 for(
size_t i=0; i<
size; i++){
523 temp[i] =
exp((*
this)[i]);}
537 for(
size_t i=0; i<
size; i++){
538 temp[i] =
log((*
this)[i]);}
552 for(
size_t i=0; i<
size; i++){
553 temp[i] =
sin((*
this)[i]);}
567 for(
size_t i=0; i<
size; i++){
568 temp[i] =
cos((*
this)[i]);}
582 for(
size_t i=0; i<
size; i++){
583 temp[i] =
tan((*
this)[i]);}
597 for(
size_t i=0; i<
size; i++){
598 temp[i] =
asin((*
this)[i]);}
612 for(
size_t i=0; i<
size; i++){
613 temp[i] =
acos((*
this)[i]);}
627 for(
size_t i=0; i<
size; i++){
628 temp[i] =
atan((*
this)[i]);}
644 if(obj.size() !=
size)
645 throw std::runtime_error(
"DACE::AlgebraicVector<T>::atan2(): Vectors must have the same length.");
648 for(
size_t i=0; i<
size; i++){
649 temp[i] =
atan2((*
this)[i], obj[i]);}
663 for(
size_t i=0; i<
size; i++){
664 temp[i] =
sinh((*
this)[i]);}
678 for(
size_t i=0; i<
size; i++){
679 temp[i] =
cosh((*
this)[i]);}
693 for(
size_t i=0; i<
size; i++){
694 temp[i] =
tanh((*
this)[i]);}
709 for(
size_t i=0; i<
size; i++){
710 temp[i] =
logb((*
this)[i], b);}
724 for(
size_t i=0; i<
size; i++){
725 temp[i] =
isrt((*
this)[i]);}
739 for(
size_t i=0; i<
size; i++){
740 temp[i] =
sqr((*
this)[i]);}
754 for(
size_t i=0; i<
size; i++){
755 temp[i] =
minv((*
this)[i]);}
770 for(
size_t i=0; i<
size; i++){
771 temp[i] =
root((*
this)[i],p);}
785 for(
size_t i=0; i<
size; i++){
786 temp[i] =
asinh((*
this)[i]);}
800 for(
size_t i=0; i<
size; i++){
801 temp[i] =
acosh((*
this)[i]);}
815 for(
size_t i=0; i<
size; i++){
816 temp[i] =
atanh((*
this)[i]);}
833 for(
size_t i=0; i<
size; i++){
834 norm = norm +
sqr((*
this)[i]);}
847 for(
size_t i=0; i<
size; i++){
848 temp[i] = (*this)[i]*
norm;}
901 template<
typename U> std::ostream& operator<<(std::ostream &out, const AlgebraicVector<U> &obj){
907 const size_t size = obj.size();
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;
923 std::string init_line;
927 getline(in, init_line);
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;
935 obj.resize(vec_size);
938 for (
size_t i = 0; in.good() && (i < vec_size); i++) {
942 if (in.peek() ==
'\n')
946 getline(in, init_line);
957 std::ostringstream strs;
958 strs << *
this << std::endl;
1135 return obj1.
atan(obj2);
1204 return obj1.
dot(obj2);
1213 return obj1.
cross(obj2);
1242 return obj.
eval(args);
1256 return obj.
eval<T>(l);
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
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
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