Simulation of a Dynamic System

This tutorial explains how to use the ACADO integrators stand-alone for the simulation of Dynamic Systems. In the current release several Runge-Kutta and a BDF integrator are available. The BDF integrator can also be used for the simulation of differential algebraic systems. All integrators allow first and second order sensitivity generation based on internal numerical or on internal automatic differentiation.

Simulation of a simple ODE

We start by integrating a very simple test ODE of the form dx(t) / dt = -x(t) with t ∈ [0,1]. The explicit solution at the time t = 1 is given by x(1) = 1/e. Now, the standard way to integrate this differential equation with ACADO Toolkit reads as follows:

#include <acado_integrators.hpp>

int main( )
{
        USING_NAMESPACE_ACADO

        DifferentialState     x;        // define the differential state x
        DifferentialEquation  f;        // introduce a differential equation f

        f << dot(x) == -x;              // define the right-hand side of the ODE

        IntegratorRK45 integrator( f ); // use a Runge Kutta integrator
                                    // (Dormand-Prince 4/5)

        double x_start[1] = { 1.0 };    // define the start value
        double t_start    =   0.0  ;    // define the time horizon
        double t_end      =   1.0  ;    // t in [0,1]

        integrator.set( "IntegratorPrintLevel",PL_MEDIUM ); // set a print-level
        integrator.integrate( x_start,t_start,t_end );      // start integration

        return 0;
}

Compiling and running the above piece of code leads to the following output:

        x[0] = 3.6787698129972368e-01
    RK: number of steps:  6      

i.e. the Runge Kutta integrator needs 6 steps to obtain the result. The accuracy of the result depends of course on the tolerance options. How these options can be specified is explained below.

Obtaining the results of the integration

In order to obtain the result of the integration for example the following routine can be used:

#include <acado_integrators.hpp>
        
int main( )
{
        USING_NAMESPACE_ACADO
        
        DifferentialState     x;     // define the differential state x
        DifferentialEquation  f;     // introduce a differential equation f
        
        // ... (same as above)
        
        integrator.integrate( x_start,t_start,t_end );  // start integration
        
        Vector xEnd(f.getDim());     // construct a vector with dimension n_x
        integrator.getX( &xEnd );    // obtain the result from the integrator
        xEnd.print();                // e.g. print the result on the terminal
        
        return 0;
}

Please note that the above tutorial code makes use of the ACADO matrix vector class, i.e. the result is stored in ACADO vector format. It is of course also possible to write the result into a simple " double* ". For this aim, the double pointer must be allocated with the correct dimension (here the dimension of the right-hand-side function f):

  #include <acado_integrators.hpp>

  int main( ){

    USING_NAMESPACE_ACADO

    // ... (same as above)

    double  xEnd[f.getDim()];   // construct a double* with dimension n_x
    integrator.getX( &xEnd );   // obtain the result from the integrator

    return 0;
  }

User options

work in progress

Next example: Sensitivity Generation for Dynamic Systems



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