Stoch_simul:problems with the second-order approximation


When trying to solve a model using a second-order approximation (I’m using matlab 2011a and either dynare 4.3.1 or 4.1.0) the simulation breaks down because I get problems with “std::bad_alloc” - full error message see below. The model runs when using a first-order approximation, although in dynare 4.3.1 it complains about that the “Matrix is close to singular or badly scaled” (RCOND = 3.139880e-017) but the program eventually runs through (dynare 4.1.0 runs without problems). My guess is that the problems are either due to the singularity problems or to memory problems - the model is quite large.

Does anyone has an idea about what might be the cause of the “std::bad_alloc” problem?


Andreas Westermark

Error message:

Configuring Dynare …
[mex] Generalized QZ.
[mex] Sylvester equation solution.
[mex] Kronecker products.
[mex] Sparse kronecker products.
[mex] Bytecode evaluation.
[mex] k-order perturbation solver.
[mex] k-order solution simulation.

Starting Dynare (version 4.1.0).
Starting preprocessing of the model file …
Found 7673 equation(s).
Evaluating expressions…done
Computing static model derivatives:

  • order 1
    Computing dynamic model derivatives:
  • order 1
  • order 2
    terminate called after throwing an instance of 'std::bad_alloc’
    what(): std::bad_alloc

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application’s support team for more information.

Hi, could you check, whether the problem persists with 4.3.2. If yes, please post or send me the mod-file so we can check if there is a bug.

I got the same results with 4.3.2, unfortunately. There seems to be some problem with uploading files - maybe because of the size. Do you have an e-mail address that I can send it to?



This error message means that the Dynare preprocessor ran out of memory. Under Windows, we distribute a 32-bit binary, which means that it is limited to 4Gb of RAM. On my machine, I let the program run until it took 7Gb of RAM, then killed it because it was making my machine unusable.

Essentially your model is too big and very nonlinear, so that 2nd order derivatives are huge expressions. Even if we were able to improve the preprocessor so that it consumes less memory, MATLAB would probably be unable to handle the dynamic file.

I think you only have two options: stick at first order, or simplify your model.