simple_function_test.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 
34 #include <time.h>
35 
40 
41 
42 int main( ){
43 
45 
46 
47  // DEFINE A VALRIABLE: (e.g. a differential state)
48  // ------------------------------------------------
50  Parameter p,q;
51 
52  // DEFINE THE RIGHT-HAND-SIDE-FUNCTION:
53  // ------------------------------------
54  Function f ;
55 
56  f << x + p + q ;
57  f << -x ;
58  f << x+y ;
59  f << x-y ;
60  f << x*y ;
61  f << x/y ;
62  f << pow(x,3) ;
63 
64  f << pow(x,y) ;
65  f << exp(x) ;
66 
67  f << ln(x) ;
68 
69  f << sin(x) ;
70  f << cos(x) ;
71  f << tan(x) ;
72 
73  f << asin(x) ;
74  f << acos(x) ;
75  f << atan(x) ;
76 
77  f << sqrt(x) ;
78 
79 
80 // TEST THE FUNCTION f:
81 // --------------------
82 
83  printf("dim = %d \n", f.getDim() );
84  printf("nx = %d \n", f.getNX() );
85  printf("np = %d \n", f.getNP() );
86 
87 
88  f.substitute( VT_PARAMETER, 0, 1.0 );
89 
90  printf("dim = %d \n", f.getDim() );
91  printf("nx = %d \n", f.getNX() );
92  printf("np = %d \n", f.getNP() );
93 
94 
95 
96  int x_index, y_index, q_index;
97 
98  x_index = f.index(VT_DIFFERENTIAL_STATE,0);
99  y_index = f.index(VT_DIFFERENTIAL_STATE,1);
100  q_index = f.index(VT_PARAMETER ,0);
101 
102  double *xx = new double[f.getNumberOfVariables()+1];
103  double *result = new double[ f.getDim() ];
104 
105  xx[x_index] = 0.1;
106  xx[y_index] = 0.2;
107  xx[q_index] = 2.0;
108 
109  f.evaluate( 0, xx, result );
110 
111  // PRINT THE RESULTS:
112  // ------------------
113 
114  int run1;
115 
116  for( run1 = 0; run1 < f.getDim(); run1++ )
117  printf("f = %10e \n", result[run1] );
118 
119 
120  // 1.0 <= x <= 2.0;
121 
122  delete[] xx;
123  delete[] result;
124 }
125 
126 
127 
int main()
USING_NAMESPACE_ACADO IntermediateState sin(const Expression &arg)
Allows to setup and evaluate a general function based on SymbolicExpressions.
Definition: function_.hpp:59
IntermediateState sqrt(const Expression &arg)
IntermediateState atan(const Expression &arg)
#define USING_NAMESPACE_ACADO
DVector evaluate(const EvaluationPoint &x, const int &number=0)
Definition: function.cpp:520
IntermediateState asin(const Expression &arg)
IntermediateState pow(const Expression &arg1, const Expression &arg2)
IntermediateState tan(const Expression &arg)
returnValue substitute(VariableType variableType_, int index_, double sub_)
Definition: function.cpp:290
IntermediateState cos(const Expression &arg)
int getNP() const
Definition: function.cpp:233
IntermediateState acos(const Expression &arg)
int getDim() const
int index(VariableType variableType_, int index_) const
Definition: function.cpp:176
IntermediateState ln(const Expression &arg)
int getNX() const
Definition: function.cpp:207
IntermediateState exp(const Expression &arg)
int getNumberOfVariables() const
Definition: function.cpp:264


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