automatic_backward_differentiation.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ACADO Toolkit.
3  *
4  * ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
5  * Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
6  * Milan Vukov, Rien Quirynen, KU Leuven.
7  * Developed within the Optimization in Engineering Center (OPTEC)
8  * under supervision of Moritz Diehl. All rights reserved.
9  *
10  * ACADO Toolkit is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 3 of the License, or (at your option) any later version.
14  *
15  * ACADO Toolkit is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with ACADO Toolkit; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  *
24  */
25 
26 
27 
34 #include <acado_integrators.hpp>
35 
36 using namespace std;
37 
39 
40 /* >>> start tutorial code >>> */
41 int main()
42 {
44 
45  // DEFINE VALRIABLES:
46  // ---------------------------
48 
49  Function f;
50 
51  f << (x+1)*(y+1) + y*x*y;//pow(y,3);
52  f << x;
53  f << y;
54 
55  // EVALUATE THE FUNCTION f:
56  // ------------------------
57  EvaluationPoint z(f);
58 
59  DVector diffState(2);
60 
61  diffState(0) = 1.0;
62  diffState(1) = 2.0;
63 
64  z.setX( diffState );
65 
66  DVector ff = f(z);
67 
68  ff.print();
69 
70  // COMPUTE THE BACKWARD DERIVATIVE:
71  // --------------------------------
72 
73  DVector seed(f.getDim());
74 
75  seed(0) = 1.0;
76  seed(1) = 0.0;
77  seed(2) = 0.0;
78 
79  EvaluationPoint df(f);
80 
81  f.AD_backward( seed, df );
82 
83  df.getX().print(cout, "df");
84 
85  return 0;
86 }
87 /* <<< end tutorial code <<< */
88 
89 
Allows to setup and evaluate a general function based on SymbolicExpressions.
Definition: function_.hpp:59
#define USING_NAMESPACE_ACADO
Allows to setup function evaluation points.
returnValue setX(const DVector &x)
DVector getX() const
int getDim() const
virtual returnValue print(std::ostream &stream=std::cout, const std::string &name=DEFAULT_LABEL, const std::string &startString=DEFAULT_START_STRING, const std::string &endString=DEFAULT_END_STRING, uint width=DEFAULT_WIDTH, uint precision=DEFAULT_PRECISION, const std::string &colSeparator=DEFAULT_COL_SEPARATOR, const std::string &rowSeparator=DEFAULT_ROW_SEPARATOR) const
Definition: vector.cpp:97
returnValue AD_backward(const DVector &seed, EvaluationPoint &df, const int &number=0)
Definition: function.cpp:546
USING_NAMESPACE_ACADO int main()


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:28