C++ alternatives for simulating dynamic systems

I'm looking for alternatives to Matlab/Simulink and Dymola for simulating a non-linear dynamic system. I know it's possible to implement the time-domain behavior without a lot of code and a good simulator template which would do fixed-step simulation, but I don't want to re-invent the wheel.

I'm basically looking for a template library that allows me to define my system, pass it to a simulator and analyze the results using other C++ libraries. The results would feed a system identifcation code that adjusts the simulated system to data gathered in experiments. Later, I'd like to use the same set of libraries to design a controller for my real system.

I don't want to use Matlab/Simulink or Dymola because I don't have access to them at home and I don't want to buy them. Matlab, Simulink, system identification toolbox and all other toolboxes I might need for this project are way too expensive for me as a single person.

A google search revealed some candidates, but they don't seem to be very active. The most recent update I found was in 2011. Does anyone here actually use such a library and can recommend one?

• Do you really need a templated library? Numerical libraries tend to sacrifice generality for speed by operating on double precision floating-point numbers. Apr 1 '13 at 18:15
• I was thinking about templates not for the underlying datatype, but on a higher level. I don't think speed will really be an issue. Apr 1 '13 at 20:15

If you're looking for something with a feature set roughly equivalent to that of MATLAB, but templated C++, Boost.odeint is probably the closest you'll get, replacing the NDF/BDF methods in ode15s with 4th-order Rosenbrock methods and no DAE solution capability.

Trilinos is the big templated C++ numerical library out there, written by Sandia National Laboratories. With it, you can probably do almost anything you can think of, including automatic differentiation of your dynamical system to generate Jacobian matrix information, if you so choose. In the design space of C++ templated libraries you could use for nonlinear dynamical systems, it is probably the other extreme in terms of features and learning curve.

There aren't many established, templated C++ libraries for dynamical systems out there. Most are written in C or Fortran (e.g., SUNDIALS, Ernst Hairer's collection of codes).

• Thanks for your remarks on the scope of both libraries, I'll see what fits best. Apr 2 '13 at 20:49

The latest boost library has numerical ode solvers -

http://www.boost.org/doc/libs/1_53_0/libs/numeric/odeint/doc/html/index.html

• Since the implicit solvers are based on Boost.uBLAS, those solvers will be slow. I guess if performance isn't an issue, then this library will be useful, but if performance isn't an issue, an interpreted language with appropriate libraries would probably speed development more than C++, all other things (language mastery, for one) being equal. Apr 1 '13 at 18:46
• As I noted in a comment above, I don't think speed will be an issue. To be honest, I feel more comfortable with lower level languages, assembler for 8-bit AVRs being the one I "mastered" before all others. Then come C, C++ (more or less) and languages like Matlab, Perl (all noise, but I've used them successfully). So I think C++ will pay off, even more so since I know my way around boost. Apr 1 '13 at 20:20
• @GeoffOxberry This library allows you to use [simunova.com/node/33](MTL) which should have decent performance. Please check the examples provided with this library - boost.org/doc/libs/1_53_0/libs/numeric/odeint/doc/html/… Apr 2 '13 at 11:02
• @Rajeev: I saw that. I also saw that they're trying to enable interoperability with CUDA (via Thrust). Their only benchmark on their website right now is a 3 equation Lorenz attractor. The ODE integrator community has developed suites of test problems (each suited to different numerical methods) that they could use for performance testing, but they haven't done so. And while they do mention the possibility of using other linear algebra libraries, they point out in the docs that certain interfaces require uBLAS data structures. Apr 2 '13 at 15:15