Dynamical Systems
Simulation Library in C++

In Portuguese

Download the library for Linux (6k): Dynamical Systems Simulation in C++
Download the library for DOS/Borland C++ 3.1 including plotting functions (79k): Dynamical Systems Simulation in C++
Introduction
This library was developed during my undergraduation on Electrical Engineering at Universidade Federal de Minas Gerais. The goal is to produce an useful and easy programming tool for simulation of Dynamical Systems represented in the space state.
Tip: In the DOS implementation, together with the numerical routines to calculate the temporal evolution of a Dynamical System, there is a set of classes designed to plot and to store the results.
Philosophy Characteristics

One of the objectives in this project is to construct friendly implemented classes. The user must supply minimal information to getting started.
The main ContinuousDynamicalSystem class characteristics are:

How to Use
The simplest way is to use the predefined macros listed below.

In your header file (.H)

DECLARE_CONTINUOUS_DYNAMICAL_SYSTEM(Name)

END_DECLARATION

where "Name" is the name of the derived class (the particular type of Dynamical System like Inverted_pendulum, Lorenz, etc).
If you want inputs in your system, you must write:

DECLARE_CONTINUOUS_DYNAMICAL_SYSTEM(Name)

DECLARE_INPUTS;

END_DECLARATION

If you want outputs:

DECLARE_CONTINUOUS_DYNAMICAL_SYSTEM(Name)

DECLARE_OUTPUTS;

END_DECLARATION

If you want inputs *and* outputs:

DECLARE_CONTINUOUS_DYNAMICAL_SYSTEM(Name)

DECLARE_INPUTS;
DECLARE_OUTPUTS;

END_DECLARATION

In your definition file (.CPP,.CC etc)

Write these macros in the global scope.
Define the Differential Equation System that describes the Dynamical System behaviour:

DEFINE_DIFFERENTIAL_EQUATION_SYSTEM(Name)

xdot[0] = p[0]*x[0] + x[1] + u[1];
xdot[1] = x[1] - p[1]*x[2]*u[0];
xdot[2] = x[0] - u[2];

END_DEFINITION

where:
xdot[n] - the nth state variable derivative.
x[n] - the nth state variable.
p[n] - the nth parameter.
u[n] - the nth input signal.
If you has declared inputs and/or outputs, you must write (for example):

DEFINE_INPUTS

u[0] = 5.0;
u[1] = t;
u[2] = sin(t) - sqrt(x[0]);

END_DEFINITION

DEFINE_OUTPUTS

y[0] = x[0];
y[1] = (x[2] - x[1])/p[0];

END_DEFINITION

In the scope of MAIN or other function

Constructs the objects with the data type you wish:

Name system1,system2;        // Linux implementation.

Name<float> system1,system2; // For the DOS implementation.

Set the parameters and the time step of integration (for the Runge-Kutta fouth order algorithm).

system1.SetParameter(0, 1.34);
system1.SetParameter(1, 1.5);
system1.SetTimeStep(0.001);

system2.SetParameter(0, 2.4);
system2.SetParameter(1, 5.2);
system2.SetTimeStep(0.01);

Now, you can calculate the next states of the system(s):

system1.Evolve(); // go to the time t (current) + time_step.
system1.Evolve(tf); // go to the time tf through steps of time_step magnitude.
system1.Evolve(tf,dt); // go to the time tf through steps of dt.

Read the information that you need:

state = system1.GetStateVar(0);
out = system1.Output(1);
t = system1.GetTime();

Final Words
See the example for more details (files example.cpp and example.h).
Please, any sugestions send me an e-mail. I will really appreciate.

E-mail: torres@cpdee.ufmg.br

Download the library for Linux (6k): Dynamical Systems Simulation in C++
Download the library for DOS/Borland C++ 3.1 including plotting functions (79k): Dynamical Systems Simulation in C++