dev_numeric_differentiation2.cpp
Go to the documentation of this file.
00001 /*
00002  *    This file is part of ACADO Toolkit.
00003  *
00004  *    ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
00005  *    Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
00006  *    Milan Vukov, Rien Quirynen, KU Leuven.
00007  *    Developed within the Optimization in Engineering Center (OPTEC)
00008  *    under supervision of Moritz Diehl. All rights reserved.
00009  *
00010  *    ACADO Toolkit is free software; you can redistribute it and/or
00011  *    modify it under the terms of the GNU Lesser General Public
00012  *    License as published by the Free Software Foundation; either
00013  *    version 3 of the License, or (at your option) any later version.
00014  *
00015  *    ACADO Toolkit is distributed in the hope that it will be useful,
00016  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  *    Lesser General Public License for more details.
00019  *
00020  *    You should have received a copy of the GNU Lesser General Public
00021  *    License along with ACADO Toolkit; if not, write to the Free Software
00022  *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00023  *
00024  */
00025 
00026 
00027 
00034 #include <time.h>
00035 #include <acado_toolkit.hpp>
00036 
00037 
00038 /* >>> start tutorial code >>> */
00039 void my_function( double *x_, double *f ){
00040 
00041 //  double          t =  x_[ 0];    // the time
00042     double          x =  x_[ 1];    // the first  differential state
00043     double          y =  x_[ 2];    // the second differential state
00044 
00045     f[0] = x*x + pow(y,3);
00046 }
00047 
00048 int main( ){
00049 
00050     USING_NAMESPACE_ACADO
00051 
00052     Function               f   ;
00053 
00054     const int  dim = 1;  // the dimension of the right hand side
00055     const int  nt  = 1;  // the explicit time dependence
00056     const int  nx  = 2;  // the number of differential states
00057     const int  na  = 0;  // the number of algebraic states
00058     const int  nu  = 0;  // the number of controls
00059     const int  nv  = 0;  // the number of integer controls
00060     const int  np  = 0;  // the number of parameters
00061     const int  nq  = 0;  // the number of integer parameters
00062     const int  nw  = 0;  // the number of disturbances
00063     const int  ndx = 0;  // the number of differential state derivatives
00064 
00065     // Code cannot be even compiled!
00066 //    f.setCFunction( dim, nt, nx, na, nu, nv, np, nq, nw, ndx, my_function );
00067 //
00068 //    // TEST THE FUNCTION f:
00069 //    // --------------------
00070 //       int x_index, y_index;
00071 //
00072 //       x_index = f.index(VT_DIFFERENTIAL_STATE,0);
00073 //       y_index = f.index(VT_DIFFERENTIAL_STATE,1);
00074 //
00075 //       double *xx     = new double[f.getNumberOfVariables()+1];
00076 //       double *lambda = new double[f.getNumberOfVariables()+1];
00077 //       double *mu     = new double[f.getNumberOfVariables()+1];
00078 //       double *mu_    = new double[f.getNumberOfVariables()+1];
00079 //       double *ff     = new double[f.getDim()                ];
00080 //       double *df1    = new double[f.getDim()                ];
00081 //       double *df2    = new double[f.getDim()                ];
00082 //       double *ddf    = new double[f.getDim()                ];
00083 //
00084 //       df1[0] = 0.0;
00085 //       df2[0] = 0.0;
00086 //       ddf[0] = 0.0;
00087 //
00088 //       xx[x_index] = 1.0;
00089 //       xx[y_index] = 1.0;
00090 //
00091 //       lambda[x_index] = 0.5;
00092 //       lambda[y_index] = 1.0;
00093 //
00094 //       mu[x_index] = 1.0;
00095 //       mu[y_index] = 0.5;
00096 //
00097 //       mu_[x_index] = 0.0;
00098 //       mu_[y_index] = 0.0;
00099 //
00100 //    // FORWARD DIFFERENTIATION:
00101 //    // (FIRST AND SECOND ORDER DERIVATIVES)
00102 //    // ------------------------------------
00103 //       f.AD_forward(  0, xx, lambda, ff, df1 );
00104 //       f.AD_forward2( 0, mu, mu_, df2, ddf );
00105 //
00106 //    // PRINT THE RESULTS:
00107 //    // ------------------
00108 //       printf("      x  = %10.16e \n",     xx[x_index] );
00109 //       printf("      y  = %10.16e \n",     xx[y_index] );
00110 //       printf("lambda_x = %10.16e \n", lambda[x_index] );
00111 //       printf("lambda_y = %10.16e \n", lambda[y_index] );
00112 //       printf("mu_x     = %10.16e \n",     mu[x_index] );
00113 //       printf("mu_y     = %10.16e \n",     mu[y_index] );
00114 //       printf("      f  = %10.16e \n",     ff[0      ] );
00115 //       printf("     df1 = %10.16e \n",    df1[0      ] );
00116 //       printf("     df2 = %10.16e \n",    df2[0      ] );
00117 //       printf("    ddf  = %10.16e \n",    ddf[0      ] );
00118 //
00119 //    delete[] xx;
00120 //    delete[] lambda;
00121 //    delete[] mu;
00122 //    delete[] mu_;
00123 //    delete[] ff;
00124 //    delete[] df1;
00125 //    delete[] df2;
00126 //    delete[] ddf;
00127 
00128     return 0;
00129 }
00130 /* <<< end tutorial code <<< */
00131 
00132 


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Sat Jun 8 2019 19:36:57