examples/integrator/harmonic_oscillator.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 #include <acado_gnuplot.hpp>
37 
38 
39 int main( ){
40 
42 
43 
44  // Define a Right-Hand-Side:
45  // -------------------------
46 
48 
50 
51  f << dot(x) == y;
52  f << dot(y) == -x;
53 
54 
55  // Define an integrator:
56  // ---------------------
57 
58  IntegratorRK45 integrator( f );
59  integrator.set( INTEGRATOR_PRINTLEVEL, MEDIUM );
60  integrator.set( PRINT_INTEGRATOR_PROFILE, YES );
61 
62  // Define an initial value:
63  // ------------------------
64  double x_start[2] = { 0.0, 1.0 };
65  Grid timeInterval( 0.0, 2.0*M_PI, 100 );
66 
67  integrator.freezeAll();
68  integrator.integrate( timeInterval, x_start );
69 
70 
71  // GET THE RESULTS
72  // ---------------
73 
74  VariablesGrid differentialStates;
75  integrator.getX( differentialStates );
76 
77  GnuplotWindow window;
78  window.addSubplot( differentialStates(0) );
79  window.addSubplot( differentialStates(1) );
80 
81  window.plot();
82 
83 
84 // DVector seed(2);
85 //
86 // seed( 0 ) = 1.0;
87 // seed( 1 ) = 0.0;
88 //
89 // integrator.setForwardSeed( 1, seed );
90 // integrator.integrateSensitivities();
91 //
92 // VariablesGrid sens;
93 // integrator.getForwardSensitivities( sens, 1 );
94 //
95 // GnuplotWindow window2;
96 // window2.addSubplot( sens(0) );
97 // window2.addSubplot( sens(1) );
98 // window2.plot();
99 
100 
101  return 0;
102 }
103 
104 
105 
returnValue getX(DVector &xEnd) const
virtual returnValue plot(PlotFrequency _frequency=PLOT_IN_ANY_CASE)
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 conveniently handle (one-dimensional) grids consisting of time points.
Definition: grid.hpp:58
returnValue addSubplot(PlotWindowSubplot &_subplot)
#define YES
Definition: acado_types.hpp:51
#define M_PI
Definition: acado_utils.hpp:54
virtual returnValue freezeAll()
Expression dot(const Expression &arg)
Implements the Runge-Kutta-45 scheme for integrating ODEs.
Provides an interface to Gnuplot for plotting algorithmic outputs.
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:39