examples/integration_algorithm/getting_started.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_gnuplot.hpp>
36 
37 using namespace std;
38 
40 
41 /* >>> start tutorial code >>> */
42 int main( )
43 {
44  // Define a Right-Hand-Side:
45  // -------------------------
48  TIME t;
49 
50  f << dot(x) == -x + sin(0.01 * t);
51 
52  // Define an initial value:
53  // ------------------------
54 
55  DVector xStart(1);
56  xStart(0) = 1.0;
57 
58  double tStart = 0.0;
59  double tEnd = 1000.0;
60 
61  Grid timeHorizon(tStart, tEnd, 2);
62  Grid timeGrid(tStart, tEnd, 20);
63 
64  // Define an integration algorithm:
65  // --------------------------------
66 
67  IntegrationAlgorithm intAlg;
68 
69  intAlg.addStage(f, timeHorizon);
70 
71  intAlg.set(INTEGRATOR_TYPE, INT_BDF);
73  intAlg.set(INTEGRATOR_TOLERANCE, 1.0e-3);
75  intAlg.set(PLOT_RESOLUTION, HIGH);
76 
77  GnuplotWindow window;
78  window.addSubplot(x, "x");
79 
80  intAlg << window;
81 
82  // START THE INTEGRATION
83  // ----------------------
84 
85  intAlg.integrate(timeHorizon, xStart);
86 
87  // GET THE RESULTS
88  // ---------------
89 
90  VariablesGrid differentialStates;
91  intAlg.getX(differentialStates);
92 
93  cout << "x = " << endl << differentialStates << endl;
94 
95  DVector xEnd;
96  intAlg.getX(xEnd);
97 
98  cout << "xEnd = " << endl << xEnd << endl;
99 
100  return 0;
101 }
102 /* <<< end tutorial code <<< */
USING_NAMESPACE_ACADO IntermediateState sin(const Expression &arg)
#define USING_NAMESPACE_ACADO
Provides a time grid consisting of vector-valued optimization variables at each grid point...
Allows to conveniently handle (one-dimensional) grids consisting of time points.
Definition: grid.hpp:58
returnValue getX(DVector &xEnd) const
returnValue integrate(VariablesGrid *x, VariablesGrid *xa, VariablesGrid *p, VariablesGrid *u, VariablesGrid *w)
returnValue addSubplot(PlotWindowSubplot &_subplot)
returnValue set(OptionsName name, int value)
Definition: options.cpp:126
#define YES
Definition: acado_types.hpp:51
User-interface to integrate a DynamicSystem, possibly over multiple stages.
Expression dot(const Expression &arg)
virtual returnValue addStage(const DynamicSystem &dynamicSystem_, const Grid &stageIntervals, const IntegratorType &integratorType_=INT_UNKNOWN)
Provides an interface to Gnuplot for plotting algorithmic outputs.
USING_NAMESPACE_ACADO int main()
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:39