SLIP  1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Polynomial.hpp
Go to the documentation of this file.
1 /*
2  * Copyright(c):
3  * Signal Image and Communications (SIC) Department
4  * http://www.sic.sp2mi.univ-poitiers.fr/
5  * - University of Poitiers, France http://www.univ-poitiers.fr
6  * - XLIM Institute UMR CNRS 7252 http://www.xlim.fr/
7  *
8  * and
9  *
10  * D2 Fluid, Thermic and Combustion
11  * - University of Poitiers, France http://www.univ-poitiers.fr
12  * - PPRIME Institute - UPR CNRS 3346 http://www.pprime.fr
13  * - ISAE-ENSMA http://www.ensma.fr
14  *
15  * Contributor(s):
16  * The SLIP team,
17  * Benoit Tremblais <tremblais_AT_sic.univ-poitiers.fr>,
18  * Laurent David <laurent.david_AT_lea.univ-poitiers.fr>,
19  * Ludovic Chatellier <ludovic.chatellier_AT_univ-poitiers.fr>,
20  * Lionel Thomas <lionel.thomas_AT_univ-poitiers.fr>,
21  * Denis Arrivault <arrivault_AT_sic.univ-poitiers.fr>,
22  * Julien Dombre <julien.dombre_AT_univ-poitiers.fr>.
23  *
24  * Description:
25  * The Simple Library of Image Processing (SLIP) is a new image processing
26  * library. It is written in the C++ language following as much as possible
27  * the ISO/ANSI C++ standard. It is consequently compatible with any system
28  * satisfying the ANSI C++ complience. It works on different Unix , Linux ,
29  * Mircrosoft Windows and Mac OS X plateforms. SLIP is a research library that
30  * was created by the Signal, Image and Communications (SIC) departement of
31  * the XLIM, UMR 7252 CNRS Institute in collaboration with the Fluids, Thermic
32  * and Combustion departement of the P', UPR 3346 CNRS Institute of the
33  * University of Poitiers.
34  *
35  * The SLIP Library source code has been registered to the APP (French Agency
36  * for the Protection of Programs) by the University of Poitiers and CNRS,
37  * under registration number IDDN.FR.001.300034.000.S.P.2010.000.21000.
38 
39  * http://www.sic.sp2mi.univ-poitiers.fr/slip/
40  *
41  * This software is governed by the CeCILL-C license under French law and
42  * abiding by the rules of distribution of free software. You can use,
43  * modify and/ or redistribute the software under the terms of the CeCILL-C
44  * license as circulated by CEA, CNRS and INRIA at the following URL
45  * http://www.cecill.info.
46  * As a counterpart to the access to the source code and rights to copy,
47  * modify and redistribute granted by the license, users are provided only
48  * with a limited warranty and the software's author, the holder of the
49  * economic rights, and the successive licensors have only limited
50  * liability.
51  *
52  * In this respect, the user's attention is drawn to the risks associated
53  * with loading, using, modifying and/or developing or reproducing the
54  * software by the user in light of its specific status of free software,
55  * that may mean that it is complicated to manipulate, and that also
56  * therefore means that it is reserved for developers and experienced
57  * professionals having in-depth computer knowledge. Users are therefore
58  * encouraged to load and test the software's suitability as regards their
59  * requirements in conditions enabling the security of their systems and/or
60  * data to be ensured and, more generally, to use and operate it in the
61  * same conditions as regards security.
62  *
63  * The fact that you are presently reading this means that you have had
64  * knowledge of the CeCILL-C license and that you accept its terms.
65  */
66 
67 
68 
75 #ifndef SLIP_POLYNOMIAL_HPP
76 #define SLIP_POLYNOMIAL_HPP
77 #include <iostream>
78 #include <iterator>
79 #include <cassert>
80 #include <numeric>
81 #include <algorithm>
82 #include <complex>
83 #include <cstddef>
84 #include <string>
85 #include "Array.hpp"
86 #include "Vector.hpp"
87 #include "Matrix.hpp"
88 #include "convolution.hpp"
89 #include "statistics.hpp"
90 #include "linear_least_squares.hpp"
91 #include "linear_algebra_eigen.hpp"
92 #include "polynomial_algo.hpp"
93 
94 #include <boost/serialization/access.hpp>
95 #include <boost/serialization/split_member.hpp>
96 #include <boost/serialization/string.hpp>
97 #include <boost/serialization/complex.hpp>
98 #include <boost/serialization/version.hpp>
99 
100 namespace slip
101 {
102 
103 template <typename T>
105 
106 template <typename T>
107 std::ostream& operator<<(std::ostream & out,
108  const Polynomial<T>& v);
109 
110 template<typename T>
111 bool operator==(const Polynomial<T>& x,
112  const Polynomial<T>& y);
113 
114 template<typename T>
115 bool operator!=(const Polynomial<T>& x,
116  const Polynomial<T>& y);
117 
118 template<typename T>
119 bool operator<(const Polynomial<T>& x,
120  const Polynomial<T>& y);
121 
122 template<typename T>
123 bool operator>(const Polynomial<T>& x,
124  const Polynomial<T>& y);
125 
126 template<typename T>
127 bool operator<=(const Polynomial<T>& x,
128  const Polynomial<T>& y);
129 
130 template<typename T>
131 bool operator>=(const Polynomial<T>& x,
132  const Polynomial<T>& y);
133 
148 template <typename T>
149 class Polynomial
150 {
151 public :
152 
153  typedef T value_type;
154  typedef Polynomial<T> self;
155  typedef const Polynomial<T> const_self;
156 
157  typedef value_type* pointer;
158  typedef const value_type* const_pointer;
160  typedef const value_type& const_reference;
161 
162  typedef ptrdiff_t difference_type;
163  typedef std::size_t size_type;
164 
165  typedef pointer iterator;
167 
168  typedef std::reverse_iterator<iterator> reverse_iterator;
169  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
170 
171 
172  //default iterator_category of the container
173  typedef std::random_access_iterator_tag iterator_category;
174 
179 
183  Polynomial();
184 
189  Polynomial(const size_type n);
190 
196  Polynomial(const size_type n,
197  const T& val);
198 
204  Polynomial(const size_type n,
205  const T* val);
206 
216  template<typename InputIterator>
217  Polynomial(InputIterator first,
218  InputIterator last)
219  {
220  assert(last > first);
221  array_->resize(last - first);
222  std::copy(first,last, this->begin());
223  }
224 
228  Polynomial(const self& rhs);
229 
233  ~Polynomial();
234 
235 
242 
249  iterator begin();
250 
257  const_iterator begin() const;
258 
265  iterator end();
266 
273  const_iterator end() const;
274 
282 
290 
298 
306 
318  friend std::ostream& operator<< <>(std::ostream & out,
319  const self& v);
335  self& operator=(const self & rhs);
336 
342  self& operator=(const T& val);
343 
349  void fill(const T& value)
350  {
351  if(value != T(0))
352  {
353  std::fill_n(this->begin(),this->size(),value);
354  }
355  else
356  {
357  array_->resize(1);
358  (*array_)[0] = value;
359  }
360  }
361 
368  void fill(const T* value)
369  {
370  std::copy(value,value + this->size(), this->begin());
371  this->kill_zeros();
372  }
373 
382  template<typename InputIterator>
383  void fill(InputIterator first,
384  InputIterator last)
385  {
386  std::copy(first,last, this->begin());
387  this->kill_zeros();
388  }
401  friend bool operator== <>(const Polynomial<T>& x,
402  const Polynomial<T>& y);
403 
410  friend bool operator!= <>(const Polynomial<T>& x,
411  const Polynomial<T>& y);
412 
419  friend bool operator< <>(const Polynomial<T>& x,
420  const Polynomial<T>& y);
421 
428  friend bool operator> <>(const Polynomial<T>& x,
429  const Polynomial<T>& y);
430 
437  friend bool operator<= <>(const Polynomial<T>& x,
438  const Polynomial<T>& y);
439 
446  friend bool operator>= <>(const Polynomial<T>& x,
447  const Polynomial<T>& y);
448 
449 
466  reference operator[](const size_type i);
467 
478  const_reference operator[](const size_type i) const;
479 
490  reference operator()(const size_type i);
491 
502  const_reference operator()(const size_type i) const;
503 
510 
516  self& operator+=(const T& val);
517  self& operator-=(const T& val);
518  self& operator*=(const T& val);
519  self& operator/=(const T& val);
520 
521  self operator-() const;
522 
523 
524  self& operator+=(const self& rhs);
525  self& operator-=(const self& rhs);
526  self& operator*=(const self& rhs);
527  // self& operator/=(const self& rhs);
528 
529 
536 
540  self& derivative();
541 
542 
547  self& integral();
548 
549 
580  double fit(iterator xi_first,
581  iterator xi_last,
582  iterator yi_first,
583  const std::size_t order);
584 
585 
594  slip::Matrix<T> companion() const;
595 
604 
609  T evaluate(const T& x) const;
610 
620  template<typename InputIterator, typename OutputIterator>
621  void multi_evaluate(InputIterator first, InputIterator last,
622  OutputIterator result) const
623  {
624  for(;first != last; first++, result++)
625  {
626  *result = this->evaluate(*first);
627  }
628 
629  }
630 
631 
632 
633 
634 
641  std::string name() const;
642 
643 
647  size_type size() const;
648 
652  size_type degree() const;
653 
659  size_type order() const;
660 
664  size_type max_size() const;
665 
669  bool empty()const;
670 
675  void swap(self& M);
676 
677 
678 
679 
680 private:
681  slip::Array<T>* array_;
682 
683 
688  void kill_zeros();
689 
696  std::size_t count_zeros(const std::size_t size);
697 
699  template<class Archive>
700  void save(Archive & ar, const unsigned int version) const
701  {
702  ar & this->array_ ;
703  }
704  template<class Archive>
705  void load(Archive & ar, const unsigned int version)
706  {
707  ar & this->array_ ;
708  }
709  BOOST_SERIALIZATION_SPLIT_MEMBER();
710 
711 };
712 
713 
722 template<typename T>
723 Polynomial<T> operator+(const Polynomial<T>& V1,
724  const Polynomial<T>& V2);
725 
733 template<typename T>
734 Polynomial<T> operator+(const Polynomial<T>& V,
735  const T& val);
736 
744 template<typename T>
745 Polynomial<T> operator+(const T& val,
746  const Polynomial<T>& V);
747 
748 
757 template<typename T>
758 Polynomial<T> operator-(const Polynomial<T>& V1,
759  const Polynomial<T>& V2);
760 
768 template<typename T>
769 Polynomial<T> operator-(const Polynomial<T>& V,
770  const T& val);
771 
779 template<typename T>
780 Polynomial<T> operator-(const T& val,
781  const Polynomial<T>& V);
782 
791 template<typename T>
792 Polynomial<T> operator*(const Polynomial<T>& V1,
793  const Polynomial<T>& V2);
794 
802 template<typename T>
803 Polynomial<T> operator*(const Polynomial<T>& V,
804  const T& val);
805 
813 template<typename T>
814 Polynomial<T> operator*(const T& val,
815  const Polynomial<T>& V);
816 
817 
818 
826  template<typename T>
827  Polynomial<T> operator/(const Polynomial<T>& V,
828  const T& val);
829 
830 }//slip::
831 
832 namespace slip
833 {
834  template<typename T>
835  inline
837  array_(new slip::Array<T>())
838  {}
839 
840  template<typename T>
841  inline
843  array_(new slip::Array<T>(n+1))
844  {}
845 
846  template<typename T>
847  inline
849  const T& val):
850  array_(new slip::Array<T>(n+1,val))
851  {}
852 
853  template<typename T>
854  inline
856  const T* val):
857  array_(new slip::Array<T>(n+1,val))
858  {
859  this->kill_zeros();
860  }
861 
862  template<typename T>
863  inline
865  array_(new slip::Array<T>((*rhs.array_)))
866  {}
867 
868  template<typename T>
869  inline
871  {
872  if(this != &rhs)
873  {
874  *array_ = *(rhs.array_);
875  }
876 
877  return *this;
878  }
879 
880  template<typename T>
881  inline
883  {
884  delete array_;
885  }
886 
887  template<typename T>
888  inline
890  {
891  array_->operator=(val);
892  return *this;
893  }
894 
895 
896  template<typename T>
897  inline
899  {
900  return array_->begin();
901  }
902 
903  template<typename T>
904  inline
906  {
907  return array_->end();
908  }
909 
910  template<typename T>
911  inline
913  {
914  return array_->begin();
915  }
916 
917  template<typename T>
918  inline
920  {
921  return array_->end();
922  }
923 
924 
925  template<typename T>
926  inline
928  {
929  return array_->rbegin();
930  }
931 
932  template<typename T>
933  inline
935  {
936  return array_->rend();
937  }
938 
939  template<typename T>
940  inline
942  {
943  return array_->rbegin();
944  }
945 
946  template<typename T>
947  inline
949  {
950  return array_->rend();
951  }
952 
953 
954  template <typename T>
955  inline
956  std::ostream& operator<<(std::ostream & out,
957  const Polynomial<T>& v)
958  {
959  if(v.size() != 0)
960  {
961  out<<v[0];
962  for(typename Polynomial<T>::size_type i = 1; i < v.size(); ++i)
963  {
964  out<<" + "<<v[i]<<" x^"<<i;
965  }
966  out<<std::endl;
967  }
968  else
969  {
970  out<<""<<std::endl;
971  }
972  return out;
973  }
974 
975  template<typename T>
976  inline
977  typename Polynomial<T>::reference Polynomial<T>::operator[](const typename Polynomial<T>::size_type i)
978  {
979  return (*array_)[i];
980  }
981 
982  template<typename T>
983  inline
984  typename Polynomial<T>::const_reference Polynomial<T>::operator[](const typename Polynomial<T>::size_type i) const
985  {
986  return (*array_)[i];
987  }
988 
989  template<typename T>
990  inline
991  typename Polynomial<T>::reference Polynomial<T>::operator()(const typename Polynomial<T>::size_type i)
992  {
993  return (*array_)(i);
994  }
995 
996  template<typename T>
997  inline
998  typename Polynomial<T>::const_reference Polynomial<T>::operator()(const typename Polynomial<T>::size_type i) const
999  {
1000  return (*array_)(i);
1001  }
1002 
1003  template<typename T>
1004  inline
1006  {
1007 
1008 
1009  if(this->degree()!=0)
1010  {
1011  Polynomial<T> Ptmp(*this);
1012  array_->resize(this->degree());
1013  for(typename Polynomial<T>::size_type i = 1; i <= Ptmp.degree(); ++i)
1014  {
1015  (*this)[i-1] = T(i)*Ptmp[i];
1016  }
1017  this->kill_zeros();
1018  }
1019  else
1020  {
1021  Polynomial<T> Ptmp(0,static_cast<T>(0));
1022  (*this) = Ptmp;
1023  }
1024  return *this;
1025  }
1026 
1027  template<typename T>
1028  inline
1030  {
1031  Polynomial<T> Ptmp(*this);
1032  array_->resize(this->size()+1);
1033  (*this)[0] = T();
1034  for(typename Polynomial<T>::size_type i = 1; i < array_->size(); ++i)
1035  {
1036  (*this)[i] = Ptmp[i-1] / i;
1037  }
1038  this->kill_zeros();
1039  return *this;
1040  }
1041 
1042  template<typename T>
1043  inline
1045  typename Polynomial<T>::iterator xi_last,
1046  typename Polynomial<T>::iterator yi_first,
1047  const std::size_t order)
1048  {
1049  typedef typename Polynomial<T>::iterator iterator;
1050 
1051  //input data
1052  std::size_t coeff_size = order + 1;
1053 
1054  //output data
1055  double chi_square = 0.0;
1056  array_->resize(coeff_size);
1058  chi_square = slip::svd_least_square<iterator,iterator,iterator>(xi_first,xi_last,yi_first,this->begin(),this->end(),power_basis);
1059  return chi_square;
1060  }
1061 
1062 
1063  template<typename T>
1064  inline
1066  {
1067 
1068  std::size_t degree = this->degree();
1069  assert(degree >= 2);
1070  slip::Matrix<T> tmp(degree,degree,T(0));
1071 
1072  T norm = (*array_)[degree];
1073  for(std::size_t k = 0, j = (tmp.cols() - 1); k < degree; j--,++k)
1074  {
1075  tmp[0][j] = -(*array_)[k] / norm;
1076  }
1077 
1078  std::size_t i = 1;
1079  std::size_t j = 0;
1080 
1081  for(std::size_t k = 1; k < degree; ++k)
1082  {
1083  tmp[i][j] = 1;
1084 
1085  i += 1;
1086  j += 1;
1087  }
1088  return tmp;
1089  }
1090 
1091  template<typename T>
1092  inline
1094  {
1095  slip::Matrix<T> companion = this->companion();
1096  slip::Vector<std::complex<T> > tmp(companion.rows());
1097  slip::eigen(companion,tmp,false);
1098 
1099  return tmp;
1100  }
1101 
1102  template<typename T>
1103  inline
1104  T Polynomial<T>::evaluate(const T& x) const
1105  {
1106  return slip::eval_horner(this->begin(),this->end(),x);
1107  }
1108 
1109 
1110  template<typename T>
1111  inline
1112  std::string
1113  Polynomial<T>::name() const {return "Polynomial";}
1114 
1115  template<typename T>
1116  inline
1117  typename Polynomial<T>::size_type Polynomial<T>::size() const {return array_->size();}
1118 
1119 
1120  template<typename T>
1121  inline
1123  if(this->size() != 0)
1124  return (this->size() - 1);
1125  else
1126  return 0;
1127  }
1128 
1129  template<typename T>
1130  inline
1132  {
1133  return this->degree();
1134  }
1135 
1136  template<typename T>
1137  inline
1139  {
1140  return typename Polynomial<T>::size_type(-1)/sizeof(T);
1141  }
1142 
1143  template<typename T>
1144  inline
1145  bool Polynomial<T>::empty()const {return array_->empty();}
1146 
1147  template<typename T>
1148  inline
1150  {
1151  array_->swap(*(V.array_));
1152  }
1153 
1154 
1155  template<typename T>
1156  inline
1158  {
1159  // std::transform(array_->begin(),array_->end(),array_->begin(),std::bind2nd(std::plus<T>(),val));
1160  //this->kill_zeros();
1161  *array_->begin()+=val;
1162  return *this;
1163  }
1164 
1165  template<typename T>
1166  inline
1168  {
1169  // std::transform(array_->begin(),array_->end(),array_->begin(),std::bind2nd(std::minus<T>(),val));
1170 // this->kill_zeros();
1171  *array_->begin()-=val;
1172  return *this;
1173  }
1174 
1175  template<typename T>
1176  inline
1178  {
1179  std::transform(array_->begin(),array_->end(),array_->begin(),std::bind2nd(std::multiplies<T>(),val));
1180  this->kill_zeros();
1181  return *this;
1182  }
1183 
1184  template<typename T>
1185  inline
1187  {
1188  std::transform(array_->begin(),array_->end(),array_->begin(),std::bind2nd(std::multiplies<T>(),T(1)/val));
1189  this->kill_zeros();
1190  return *this;
1191  }
1192 
1193 
1194  template<typename T>
1195  inline
1197  {
1198  Polynomial<T> tmp(*this);
1199  std::transform(array_->begin(),array_->end(),tmp.begin(),std::negate<T>());
1200  return tmp;
1201  }
1202 
1203  template<typename T>
1204  inline
1206  {
1207  std::size_t max_size = std::max(this->size(),rhs.size());
1208  Polynomial<T> tmp(*this);
1209  array_->resize(max_size);
1210 
1211  if(max_size == tmp.size())
1212  {
1213  std::transform((*(rhs.array_)).begin(),(*(rhs.array_)).end(),tmp.begin(),this->begin(),std::plus<T>());
1214  std::copy(tmp.begin() + rhs.size(),tmp.end(),this->begin()+rhs.size());
1215  }
1216  else
1217  {
1218  std::transform(tmp.begin(),tmp.end(),(*(rhs.array_)).begin(),this->begin(),std::plus<T>());
1219  std::copy(rhs.begin() + tmp.size(),rhs.end(),this->begin()+tmp.size());
1220 
1221  }
1222  this->kill_zeros();
1223  return *this;
1224  }
1225 
1226  template<typename T>
1227  inline
1229  {
1230  std::size_t max_size = std::max(this->size(),rhs.size());
1231  Polynomial<T> tmp(*this);
1232  array_->resize(max_size);
1233  if(max_size == tmp.size())
1234  {
1235  std::transform(tmp.begin(),tmp.begin()+rhs.size(),rhs.begin(),this->begin(),std::minus<T>());
1236  std::copy(tmp.begin() + rhs.size(),tmp.end(),this->begin()+rhs.size());
1237  }
1238  else
1239  {
1240  std::transform(tmp.begin(),tmp.end(),(*(rhs.array_)).begin(),this->begin(),std::minus<T>());
1241  std::copy(rhs.begin() + tmp.size(),rhs.end(),this->begin()+tmp.size());
1242  std::transform(this->begin()+tmp.size(),this->end(),this->begin()+tmp.size(),std::negate<T>());
1243 
1244  }
1245  this->kill_zeros();
1246  return *this;
1247  }
1248 
1249 
1250  template<typename T>
1251  inline
1253  {
1254  assert(rhs.size() > 0);
1255  assert(this->size() > 0);
1256  Polynomial Ptmp(*this);
1257 
1258  array_->resize((rhs.degree() + Ptmp.degree()) + 1);
1259  if(Ptmp.size() > rhs.size())
1260  {
1261  slip::full_convolution(Ptmp.begin(),Ptmp.end(),rhs.begin(),rhs.end(),this->begin());
1262  }
1263  else
1264  {
1265  slip::full_convolution(rhs.begin(),rhs.end(),Ptmp.begin(),Ptmp.end(),this->begin());
1266  }
1267  this->kill_zeros();
1268  return *this;
1269  }
1270 
1271 
1272  template<typename T>
1273  inline
1274  std::size_t Polynomial<T>::count_zeros(std::size_t size)
1275  {
1276  if(size != 0)
1277  {
1278  std::size_t new_size = size;
1279  if((*this)[new_size-1] == T(0))
1280  {
1281  return count_zeros(new_size-1);
1282  }
1283  else
1284  {
1285  return new_size;
1286  }
1287  }
1288  else
1289  {
1290  return 1;
1291  }
1292  }
1293 
1294  template<typename T>
1295  inline
1296  void Polynomial<T>::kill_zeros()
1297  {
1298  std::size_t new_size = this->count_zeros(this->size());
1299  if(new_size != this->size())
1300  {
1301  slip::Polynomial<T> tmp(*this);
1302  (this->array_)->resize(this->count_zeros(new_size));
1303  std::copy(tmp.begin(),tmp.begin()+new_size,this->begin());
1304  }
1305 
1306  }
1307 
1309  /* @{ */
1310  template<typename T>
1311  inline
1313  const Polynomial<T>& V2)
1314  {
1315  Polynomial<T> tmp(V1);
1316  tmp+=V2;
1317  return tmp;
1318  }
1319 
1320  template<typename T>
1321  inline
1323  const T& val)
1324  {
1325  Polynomial<T> tmp(V1);
1326  tmp+=val;
1327  return tmp;
1328  }
1329 
1330  template<typename T>
1331  inline
1332  Polynomial<T> operator+(const T& val,
1333  const Polynomial<T>& V1)
1334  {
1335  return V1 + val;
1336  }
1337 
1338  template<typename T>
1339  inline
1341  const Polynomial<T>& V2)
1342  {
1343  Polynomial<T> tmp(V1);
1344  tmp-=V2;
1345  return tmp;
1346  }
1347 
1348  template<typename T>
1349  inline
1351  const T& val)
1352  {
1353  Polynomial<T> tmp(V1);
1354  tmp-=val;
1355  return tmp;
1356  }
1357 
1358  template<typename T>
1359  inline
1360  Polynomial<T> operator-(const T& val,
1361  const Polynomial<T>& V1)
1362  {
1363  return -(V1 - val);
1364  }
1365 
1366  template<typename T>
1367  inline
1369  const Polynomial<T>& V2)
1370  {
1371  Polynomial<T> tmp(V1);
1372  tmp*=V2;
1373  return tmp;
1374  // Polynomial<T> Ptmp(V1.degree() + V2.degree());
1375 
1376 // if(V1.size() > V2.size())
1377 // {
1378 // slip::full_convolution(V1.begin(),V1.end(),V2.end(),0,V2.size()-1,Ptmp.begin());
1379 // }
1380 // else
1381 // {
1382 // slip::full_convolution(V2.begin(),V2.end(),V1.end(),0,V1.size()-1,Ptmp.begin());
1383 // }
1384 
1385 // return Ptmp;
1386  }
1387 
1388  template<typename T>
1389  inline
1391  const T& val)
1392 {
1393  Polynomial<T> tmp(V1);
1394  tmp*=val;
1395  return tmp;
1396 }
1397 
1398 template<typename T>
1399 inline
1401  const Polynomial<T>& V1)
1402 {
1403  return V1 * val;
1404 }
1405 
1406 
1407 
1408 template<typename T>
1409 inline
1411  const T& val)
1412 {
1413  Polynomial<T> tmp(V1);
1414  tmp/=val;
1415  return tmp;
1416 }
1417 /* @} */
1419  /* @{ */
1420 template<typename T>
1421 inline
1422 bool operator==(const Polynomial<T>& x,
1423  const Polynomial<T>& y)
1424 {
1425  return *(x.array_) == *(y.array_);
1426 }
1427 
1428 template<typename T>
1429 inline
1430 bool operator!=(const Polynomial<T>& x,
1431  const Polynomial<T>& y)
1432 {
1433  return !(x == y);
1434 }
1435 /* @} */
1437  /* @{ */
1438 template<typename T>
1439 inline
1440 bool operator<(const Polynomial<T>& x,
1441  const Polynomial<T>& y)
1442 {
1443  return *(x.array_) < *(y.array_);
1444 }
1445 
1446 template<typename T>
1447 inline
1448 bool operator>(const Polynomial<T>& x,
1449  const Polynomial<T>& y)
1450 {
1451  return (y < x);
1452 }
1453 
1454 template<typename T>
1455 inline
1456 bool operator<=(const Polynomial<T>& x,
1457  const Polynomial<T>& y)
1458 {
1459  return !(y < x);
1460 }
1461 
1462 template<typename T>
1463 inline
1464 bool operator>=(const Polynomial<T>& x,
1465  const Polynomial<T>& y)
1466 {
1467  return !(x < y);
1468 }
1469 /* @} */
1470 }//slip::
1471 
1472 #endif //SLIP_POLYNOMIAL_HPP
std::string name() const
Returns the name of the class.
std::size_t size_type
Definition: Polynomial.hpp:163
void fill(const T *value)
Fills the container range [begin(),begin()+size()) with a copy of the value array.
Definition: Polynomial.hpp:368
bool operator!=(const Array< T > &x, const Array< T > &y)
Definition: Array.hpp:1448
self & operator+=(const T &val)
Add val to each element of the Polynomial.
friend class boost::serialization::access
Definition: Polynomial.hpp:698
self & derivative()
Returns the derivative the polynomial.
const Polynomial< T > const_self
Definition: Polynomial.hpp:155
size_type max_size() const
Returns the maximal size (number of elements) in the Polynomial.
double fit(iterator xi_first, iterator xi_last, iterator yi_first, const std::size_t order)
Return a polynomial P(X) of degree order that minimizes sum_i (P(x(i)) - y(i))^2 to best fit the data...
Color< T > operator+(const Color< T > &V1, const Color< T > &V2)
Definition: Color.hpp:602
iterator begin()
Returns a read/write iterator that points to the first element in the Polynomial. Iteration is done i...
Definition: Polynomial.hpp:898
size_type cols() const
Returns the number of columns (second dimension size) in the Matrix.
Definition: Matrix.hpp:3512
void fill(InputIterator first, InputIterator last)
Fills the container range [begin(),begin()+size()) with a copy of the range [first,last)
Definition: Polynomial.hpp:383
value_type * pointer
Definition: Polynomial.hpp:157
reverse_iterator rend()
Returns a read/write reverse iterator that points to one before the first element in the Polynomial...
Definition: Polynomial.hpp:934
slip::Vector< std::complex< T > > roots() const
Computes the roots of the polynomial.
const value_type * const_pointer
Definition: Polynomial.hpp:158
bool operator>(const Array< T > &x, const Array< T > &y)
Definition: Array.hpp:1469
self & operator=(const self &rhs)
Assign a Polynomial.
Definition: Polynomial.hpp:870
Provides a class to manipulate 1d dynamic and generic arrays.
reference operator[](const size_type i)
Subscript access to the data contained in the Polynomial.
value_type & reference
Definition: Polynomial.hpp:159
void eigen(const Matrix1 &A, Vector1 &E, bool sort=false)
Eigen Values Computation for non symmetric matrix.
Provides some polynomial algorithms.
self & operator-=(const T &val)
bool empty() const
Returns true if the Polynomial is empty. (Thus size() == 0)
const_pointer const_iterator
Definition: Polynomial.hpp:166
ptrdiff_t difference_type
Definition: Polynomial.hpp:162
Provides some statistics algorithms.
Provides some algorithms to computes eigenvalues and eigenvectors.
size_type degree() const
Returns the degree of the Polynomial.
void copy(_II first, _II last, _OI output_first)
Copy algorithm optimized for slip iterators.
Definition: copy_ext.hpp:177
Polynomial()
Constructs a Polynomial.
Definition: Polynomial.hpp:836
size_type order() const
Returns the order of the Polynomial.
Numerical Polynomial class. This container statisfies the RandomAccessContainer concepts of the STL T...
Definition: Polynomial.hpp:104
Numerical Vector class. This container statisfies the RandomAccessContainer concepts of the Standard ...
Definition: Vector.hpp:104
self & operator*=(const T &val)
self operator-() const
reverse_iterator rbegin()
Returns a read/write reverse iterator that points to the last element in the Polynomial. Iteration is done in reverse element order.
Definition: Polynomial.hpp:927
Polynomial(InputIterator first, InputIterator last)
Contructs a Polynomial from a range.
Definition: Polynomial.hpp:217
T eval_horner(RandomAccessIterator first, RandomAccessIterator last, const T &x)
Returns the evaluation of the polynomial given throw the range [first,last) at x using the horner sch...
std::random_access_iterator_tag iterator_category
Definition: Polynomial.hpp:173
std::ostream & operator<<(std::ostream &out, const Array< T > &a)
Definition: Array.hpp:1282
void fill(const T &value)
Fills the container range [begin(),begin()+size()) with copies of value.
Definition: Polynomial.hpp:349
std::reverse_iterator< iterator > reverse_iterator
Definition: Polynomial.hpp:168
size_type rows() const
Returns the number of rows (first dimension size) in the Matrix.
Definition: Matrix.hpp:3499
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: Polynomial.hpp:169
const value_type & const_reference
Definition: Polynomial.hpp:160
void multi_evaluate(InputIterator first, InputIterator last, OutputIterator result) const
Returns the evaluation of the polynomial at each element of the range [first,last).
Definition: Polynomial.hpp:621
Provides some convolution algorithms.
reference operator()(const size_type i)
Subscript access to the data contained in the Polynomial.
size_type size() const
Returns the number of elements in the Polynomial.
T evaluate(const T &x) const
Returns the evaluation of the polynomial at x.
slip::Matrix< T > companion() const
Computes the companion matrix corresponding to polynomial coefficients.
void swap(self &M)
Swaps data with another Polynomial.
Provides a class to manipulate Numerical Matrix.
~Polynomial()
Destructor of the Polynomial.
Definition: Polynomial.hpp:882
void full_convolution(SrcIter first, SrcIter last, KernelIter kernel_first, KernelIter kernel_last, ResIter result)
Computes the full convolution of signal by a 1d-kernel.
bool operator==(const Array< T > &x, const Array< T > &y)
Definition: Array.hpp:1439
This is a linear (one-dimensional) dynamic template container. This container statisfies the RandomAc...
Definition: Array.hpp:94
Provides some linear least square algorithms.
Color< T > operator*(const Color< T > &V1, const Color< T > &V2)
Definition: Color.hpp:658
iterator end()
Returns a read/write iterator that points one past the last element in the Polynomial. Iteration is done in ordinary element order.
Definition: Polynomial.hpp:905
Provides a class to manipulate numerical vectors.
T & max(const GrayscaleImage< T > &M1)
Returns the max element of a GrayscaleImage.
Color< T > operator/(const Color< T > &V1, const Color< T > &V2)
Definition: Color.hpp:686
self & integral()
Returns the integral of the polynomial. The constant of integrationis set to zero.
bool operator>=(const Array< T > &x, const Array< T > &y)
Definition: Array.hpp:1485
Color< T > operator-(const Color< T > &V1, const Color< T > &V2)
Definition: Color.hpp:630
self & operator/=(const T &val)