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 
35 #include <acado_integrators.hpp>
36 
37 
38 /* >>> start tutorial code >>> */
39 int main( ){
40 
42 
43  // Define a Right-Hand-Side:
44  // -------------------------
47 
49 
50  a = (1.0-x*x-y*y);
51 
52  f << dot(x) == y + a + x*a + a*a;
53  f << dot(y) == -x;
54 
55  // Define an integrator:
56  // ---------------------
57  IntegratorRK45 integrator( f );
58  integrator.set( INTEGRATOR_PRINTLEVEL, MEDIUM );
59 
60  // Define an initial value:
61  // ------------------------
62  double x_start[2] = { 0.0, 1.0 };
63  double t_start = 0.0 ;
64  double t_end = 2.0*M_PI ;
65 
66 
67  // START THE INTEGRATION
68  // AND COPUTE FIRST ORDER
69  // FORWARD SENSITIVITIES:
70  // ----------------------
71  DVector seed(2);
72  seed(0) = 1.0;
73  seed(1) = 0.0;
74 
75  integrator.freezeAll();
76  integrator.integrate( t_start, t_end, x_start );
77 
78  integrator.setBackwardSeed( 1, seed );
79  integrator.integrateSensitivities();
80 
81  seed(0) = 0.0;
82  seed(1) = 1.0;
83 
84  integrator.setBackwardSeed( 1, seed );
85  integrator.integrateSensitivities();
86 
87 
88  // GET THE RESULTS
89  // ---------------
90 
91  VariablesGrid differentialStates;
92  integrator.getX( differentialStates );
93 
94  DVector Dx( 2 );
95  integrator.getBackwardSensitivities( Dx,emptyVector,emptyVector,emptyVector,1 ); // w.r.t. x0,p,u,w
96 
97  differentialStates.print( "x" );
98  Dx.print( "Dx" );
99 
100 
101  return 0;
102 }
103 /* <<< end tutorial code <<< */
104 
105 
returnValue print(std::ostream &stream=std::cout, const char *const name=DEFAULT_LABEL, const char *const startString=DEFAULT_START_STRING, const char *const endString=DEFAULT_END_STRING, uint width=DEFAULT_WIDTH, uint precision=DEFAULT_PRECISION, const char *const colSeparator=DEFAULT_COL_SEPARATOR, const char *const rowSeparator=DEFAULT_ROW_SEPARATOR) const
returnValue getX(DVector &xEnd) const
returnValue set(OptionsName name, int value)
#define USING_NAMESPACE_ACADO
Provides a time grid consisting of vector-valued optimization variables at each grid point...
#define M_PI
Definition: acado_utils.hpp:54
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
virtual returnValue freezeAll()
Expression dot(const Expression &arg)
returnValue getBackwardSensitivities(DVector &Dx_x0, DVector &Dx_p, DVector &Dx_u, DVector &Dx_w, int order) const
Definition: integrator.cpp:424
Implements the Runge-Kutta-45 scheme for integrating ODEs.
const double t_end
const double t_start
static DVector emptyVector
Definition: vector.hpp:335
returnValue integrateSensitivities()
Definition: integrator.cpp:357
returnValue setBackwardSeed(const int &order, const DVector &seed)
Definition: integrator.cpp:338
returnValue integrate(double t0, double tend, double *x0, double *xa=0, double *p=0, double *u=0, double *w=0)
Definition: integrator.cpp:207
Allows to setup and evaluate differential equations (ODEs and DAEs) based on SymbolicExpressions.


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