cheshirekow  v0.1.0
differentiate.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_DIFFERENTIATE_H_
28 #define MPBLOCKS_POLYNOMIAL_DIFFERENTIATE_H_
29 
30 
31 namespace mpblocks {
32 namespace polynomial {
33 
35 template <typename Scalar, class Exp1, class Exp2>
38  int n )
39 {
40  // the number of the derivative to compute
41  out.resize( in.size() - n );
42 
43  // initialize the output
44  for(int i=0; i < out.size(); i++)
45  out[i] = in[i+n];
46 
47  // fill the output with the initial coefficients
48  for(int i=2; i < in.size(); i++)
49  {
50  // the factor i contributes to all coefficients of the output
51  // with index >= (i-n) < (i)
52  for(int j = i-n; j < i && j < out.size(); j++)
53  out[j] *= i;
54  }
55 }
56 
57 } // namespace polynomial
58 } // namespace mpblocks
59 
60 
61 
62 
63 
64 
65 
66 
67 
68 
69 
70 
71 
72 
73 
74 #endif // DIFFERENTIATE_H_
expression template for rvalues
Definition: LValue.h:35
Size_t size() const
return the size for a vector
Definition: LValue.h:43
Size_t size() const
return the size for a vector
Definition: RValue.h:41
void resize(Size_t size)
Definition: LValue.h:75
expression template for rvalues
Definition: RValue.h:35
void differentiate(const RValue< Scalar, Exp1 > &in, LValue< Scalar, Exp2 > &out, int n)
evaluate a polynomial
Definition: differentiate.h:36