forward_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 
44  // Define a Right-Hand-Side:
45  // -------------------------
46 
49 
50  f << dot(x) == y;
51  f << dot(y) == -x;
52 
53  // Define an integrator:
54  // ---------------------
55 
56  IntegratorRK45 integrator( f );
57  integrator.set( INTEGRATOR_PRINTLEVEL, MEDIUM );
58 
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.setForwardSeed( 1, seed );
79  integrator.integrateSensitivities();
80 
81 
82  // GET THE RESULTS
83  // ---------------
84 
85  VariablesGrid differentialStates;
86  integrator.getX( differentialStates );
87 
88  DVector Dx( 2 );
89  integrator.getForwardSensitivities( Dx,1 );
90 
91  differentialStates.print( "x" );
92  Dx.print( "Dx" );
93 
94 
95  return 0;
96 }
97 /* <<< end tutorial code <<< */
98 
99 
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...
returnValue setForwardSeed(const int &order, const DVector &xSeed, const DVector &pSeed=emptyVector, const DVector &uSeed=emptyVector, const DVector &wSeed=emptyVector)
Definition: integrator.cpp:308
#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)
Implements the Runge-Kutta-45 scheme for integrating ODEs.
const double t_end
const double t_start
returnValue integrateSensitivities()
Definition: integrator.cpp:357
returnValue getForwardSensitivities(DVector &Dx, int order) const
Definition: integrator.cpp:406
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:34