integrator/simple_dae_c.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 /* >>> start tutorial code >>> */
40 
41 void ffcn_model( double *xx, double *f, void *user_data ){
42 
43  double x = xx[ 0];
44  double z = xx[ 1];
45  double p = xx[ 2];
46  double q = xx[ 3];
47 
48  f[0] = -p*x*x*z;
49  f[1] = q*q - z*z + 0.1*x;
50 
51 
52 // f << dot(x) == -p*x*x*z ;
53 // f << 0 == q*q - z*z;
54 
55 }
56 
57 
58 
59 
60 int main( ){
61 
63 
64  // DEFINE A RIGHT-HAND-SIDE:
65  // -------------------------
68  Parameter p,q;
69 
70 
71  IntermediateState is(4);
72  is(0) = x;
73  is(1) = z;
74  is(2) = p;
75  is(3) = q;
76 
77  CFunction simpledaeModel( 2, ffcn_model );
78 
79  // Define a Right-Hand-Side:
80  // -------------------------
81 
83 
84  f << simpledaeModel(is);
85 
86 
87 
88  // DEFINE AN INTEGRATOR:
89  // ---------------------
90  IntegratorBDF integrator(f);
91 
92 
93  // DEFINE INITIAL VALUES:
94  // ----------------------
95  double x0 = 1.0;
96  double z0 = 1.000000;
97 
98  double pp[2] = { 1.0, 1.0 };
99 
100  Grid interval( 0.0, 1.0, 100 );
101 
102 
103  // START THE INTEGRATION:
104  // ----------------------
105  integrator.integrate( interval, &x0, &z0, pp );
106 
107  VariablesGrid differentialStates;
108  VariablesGrid algebraicStates ;
109  VariablesGrid intermediateStates;
110 
111  integrator.getX ( differentialStates );
112  integrator.getXA( algebraicStates );
113  integrator.getI ( intermediateStates );
114 
115  GnuplotWindow window;
116  window.addSubplot( differentialStates(0) );
117  window.addSubplot( algebraicStates (0) );
118 
119  window.plot();
120 
121 
122  return 0;
123 }
124 /* <<< end tutorial code <<< */
125 
126 
returnValue getX(DVector &xEnd) const
virtual returnValue plot(PlotFrequency _frequency=PLOT_IN_ANY_CASE)
Implements the backward-differentiation formula for integrating DAEs.
#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)
returnValue getI(VariablesGrid &I) const
returnValue getXA(DVector &xaEnd) const
void ffcn_model(double *xx, double *f, void *user_data)
(no description yet)
Definition: c_function.hpp:54
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:35:04