examples/integrator/getting_started_discretized.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 
44  Control u;
45 
46  const double h = 0.01;
48 
49  const double t_start = 0.0;
50  const double t_end = 1.0;
51 
52 
53  // DEFINE A DIFFERENTIAL EQUATION:
54  // -------------------------------
55  f << next(x) == x - h*x + h*u*u;
56 
57 
58  // Define an integrator:
59  // ---------------------
60  IntegratorDiscretizedODE integrator( f );
61 
62  integrator.set( INTEGRATOR_PRINTLEVEL, MEDIUM );
63 
64 
65  // Define an initial value:
66  // ------------------------
67 
68  double x_start[1] = { 1.0 };
69  double u_start[1] = { 1.0 };
70 
71 
72  // START THE INTEGRATION
73  // ----------------------
74 
75  integrator.freezeAll();
76  integrator.integrate( t_start, t_end, x_start, 0, 0, u_start );
77 
78  // ----------------------
79  DVector seed(1);
80  seed(0) = 1.0;
81 
82  integrator.setForwardSeed( 1, emptyVector, emptyVector, seed );
83  integrator.integrateSensitivities();
84 
85  integrator.setForwardSeed( 2, emptyVector, emptyVector, seed );
86  integrator.integrateSensitivities();
87 
88 
89  // GET THE RESULTS
90  // ---------------
91 
92  VariablesGrid differentialStates;
93  integrator.getX( differentialStates );
94 
95  DVector Dx( 1 );
96  integrator.getForwardSensitivities( Dx,1 );
97 
98  differentialStates.print( "x" );
99  Dx.print( "Dx" );
100 
101 
102  return 0;
103 }
104 /* <<< end tutorial code <<< */
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...
Allows to setup and evaluate discretized differential equations based on SymbolicExpressions.
returnValue setForwardSeed(const int &order, const DVector &xSeed, const DVector &pSeed=emptyVector, const DVector &uSeed=emptyVector, const DVector &wSeed=emptyVector)
Definition: integrator.cpp:308
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()
const double t_end
const double t_start
Expression next(const Expression &arg)
static DVector emptyVector
Definition: vector.hpp:335
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
Implements a scheme for evaluating discretized ODEs.


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