cheshirekow  v0.1.0
polyval.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Josh Bialkowski (jbialk@mit.edu)
3  *
4  * This file is part of mpblocks.
5  *
6  * mpblocks is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * mpblocks is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with mpblocks. If not, see <http://www.gnu.org/licenses/>.
18  */
27 #ifndef MPBLOCKS_POLYNOMIAL_POLYVAL_H_
28 #define MPBLOCKS_POLYNOMIAL_POLYVAL_H_
29 
30 namespace mpblocks {
31 namespace polynomial {
32 
34 template <typename Scalar, class Exp>
35 Scalar polyval( const RValue<Scalar,Exp>& poly, Scalar x )
36 {
37  Scalar x_i = 1.0;
38  Scalar r = poly[0];
39 
40  for(int i=1; i < poly.size(); ++i)
41  {
42  x_i *= x;
43  r += poly[i]*x_i;
44  }
45 
46  return r;
47 }
48 
49 } // namespace polynomial
50 } // namespace mpblocks
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 #endif // POLYVAL_H_
Size_t size() const
return the size for a vector
Definition: RValue.h:41
expression template for rvalues
Definition: RValue.h:35
Scalar polyval(const RValue< Scalar, Exp > &poly, Scalar x)
evaluate a polynomial
Definition: polyval.h:35