dev_numeric_differentiation2.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 #include <acado_toolkit.hpp>
36 
37 
38 /* >>> start tutorial code >>> */
39 void my_function( double *x_, double *f ){
40 
41 // double t = x_[ 0]; // the time
42  double x = x_[ 1]; // the first differential state
43  double y = x_[ 2]; // the second differential state
44 
45  f[0] = x*x + pow(y,3);
46 }
47 
48 int main( ){
49 
51 
52  Function f ;
53 
54  const int dim = 1; // the dimension of the right hand side
55  const int nt = 1; // the explicit time dependence
56  const int nx = 2; // the number of differential states
57  const int na = 0; // the number of algebraic states
58  const int nu = 0; // the number of controls
59  const int nv = 0; // the number of integer controls
60  const int np = 0; // the number of parameters
61  const int nq = 0; // the number of integer parameters
62  const int nw = 0; // the number of disturbances
63  const int ndx = 0; // the number of differential state derivatives
64 
65  // Code cannot be even compiled!
66 // f.setCFunction( dim, nt, nx, na, nu, nv, np, nq, nw, ndx, my_function );
67 //
68 // // TEST THE FUNCTION f:
69 // // --------------------
70 // int x_index, y_index;
71 //
72 // x_index = f.index(VT_DIFFERENTIAL_STATE,0);
73 // y_index = f.index(VT_DIFFERENTIAL_STATE,1);
74 //
75 // double *xx = new double[f.getNumberOfVariables()+1];
76 // double *lambda = new double[f.getNumberOfVariables()+1];
77 // double *mu = new double[f.getNumberOfVariables()+1];
78 // double *mu_ = new double[f.getNumberOfVariables()+1];
79 // double *ff = new double[f.getDim() ];
80 // double *df1 = new double[f.getDim() ];
81 // double *df2 = new double[f.getDim() ];
82 // double *ddf = new double[f.getDim() ];
83 //
84 // df1[0] = 0.0;
85 // df2[0] = 0.0;
86 // ddf[0] = 0.0;
87 //
88 // xx[x_index] = 1.0;
89 // xx[y_index] = 1.0;
90 //
91 // lambda[x_index] = 0.5;
92 // lambda[y_index] = 1.0;
93 //
94 // mu[x_index] = 1.0;
95 // mu[y_index] = 0.5;
96 //
97 // mu_[x_index] = 0.0;
98 // mu_[y_index] = 0.0;
99 //
100 // // FORWARD DIFFERENTIATION:
101 // // (FIRST AND SECOND ORDER DERIVATIVES)
102 // // ------------------------------------
103 // f.AD_forward( 0, xx, lambda, ff, df1 );
104 // f.AD_forward2( 0, mu, mu_, df2, ddf );
105 //
106 // // PRINT THE RESULTS:
107 // // ------------------
108 // printf(" x = %10.16e \n", xx[x_index] );
109 // printf(" y = %10.16e \n", xx[y_index] );
110 // printf("lambda_x = %10.16e \n", lambda[x_index] );
111 // printf("lambda_y = %10.16e \n", lambda[y_index] );
112 // printf("mu_x = %10.16e \n", mu[x_index] );
113 // printf("mu_y = %10.16e \n", mu[y_index] );
114 // printf(" f = %10.16e \n", ff[0 ] );
115 // printf(" df1 = %10.16e \n", df1[0 ] );
116 // printf(" df2 = %10.16e \n", df2[0 ] );
117 // printf(" ddf = %10.16e \n", ddf[0 ] );
118 //
119 // delete[] xx;
120 // delete[] lambda;
121 // delete[] mu;
122 // delete[] mu_;
123 // delete[] ff;
124 // delete[] df1;
125 // delete[] df2;
126 // delete[] ddf;
127 
128  return 0;
129 }
130 /* <<< end tutorial code <<< */
131 
132 
Allows to setup and evaluate a general function based on SymbolicExpressions.
Definition: function_.hpp:59
void my_function(double *x_, double *f)
#define USING_NAMESPACE_ACADO
IntermediateState pow(const Expression &arg1, const Expression &arg2)
const int nu


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