simple_function_test.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 
00036 #include <acado/utils/acado_utils.hpp>
00037 #include <acado/user_interaction/user_interaction.hpp>
00038 #include <acado/symbolic_expression/symbolic_expression.hpp>
00039 #include <acado/function/function.hpp>
00040 
00041 
00042 int main( ){
00043 
00044     USING_NAMESPACE_ACADO
00045 
00046 
00047     // DEFINE A VALRIABLE:  (e.g. a differential state)
00048     // ------------------------------------------------
00049     DifferentialState      x,y;
00050     Parameter              p,q;
00051 
00052     // DEFINE THE RIGHT-HAND-SIDE-FUNCTION:
00053     // ------------------------------------
00054     Function f         ;
00055 
00056     f  <<  x + p + q   ;
00057     f  << -x           ;
00058     f  <<  x+y         ;
00059     f  <<  x-y         ;
00060     f  <<  x*y         ;
00061     f  <<  x/y         ;
00062     f  <<  pow(x,3)    ;
00063 
00064     f  <<  pow(x,y)    ;
00065     f  <<  exp(x)      ;
00066 
00067     f  <<  ln(x)       ;
00068 
00069     f  <<  sin(x)      ;
00070     f  <<  cos(x)      ;
00071     f  <<  tan(x)      ;
00072 
00073     f  <<  asin(x)     ;
00074     f  <<  acos(x)     ;
00075     f  <<  atan(x)     ;
00076 
00077     f  <<  sqrt(x)     ;
00078 
00079 
00080 //     TEST THE FUNCTION f:
00081 //     --------------------
00082 
00083     printf("dim = %d \n", f.getDim() );
00084     printf("nx  = %d \n", f.getNX() );
00085     printf("np  = %d \n", f.getNP() );
00086 
00087 
00088     f.substitute( VT_PARAMETER, 0, 1.0 );
00089 
00090     printf("dim = %d \n", f.getDim() );
00091     printf("nx  = %d \n", f.getNX() );
00092     printf("np  = %d \n", f.getNP() );
00093 
00094 
00095 
00096        int x_index, y_index, q_index;
00097 
00098        x_index = f.index(VT_DIFFERENTIAL_STATE,0);
00099        y_index = f.index(VT_DIFFERENTIAL_STATE,1);
00100        q_index = f.index(VT_PARAMETER         ,0);
00101 
00102        double *xx = new double[f.getNumberOfVariables()+1];
00103        double *result = new double[ f.getDim() ];
00104 
00105        xx[x_index] = 0.1;
00106        xx[y_index] = 0.2;
00107        xx[q_index] = 2.0;
00108 
00109        f.evaluate( 0, xx, result );
00110 
00111     // PRINT THE RESULTS:
00112     // ------------------
00113 
00114        int run1;
00115 
00116        for( run1 = 0; run1 < f.getDim(); run1++ )
00117            printf("f = %10e \n", result[run1] );
00118 
00119 
00120     // 1.0 <= x <= 2.0;
00121 
00122        delete[] xx;
00123        delete[] result;
00124 }
00125 
00126 
00127 


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Thu Aug 27 2015 12:00:00