# Matrix is singular to working precision problem

Hi, I’m currently working on the model by Kirchner & Van Wijnbergen (2016), and I intend to adapt it to the context of epidemics/Covid-19 for which I have included an external process from Acurio-Vasconez (2021) that exogenously determines the labor supply. Hence, the model is deterministic and is solved w/ perfect foresight. I’ve solved the steady-state analytically and followed the original code closely, yet somehow this problem keeps occurring. I’ve double-checked the equations and can’t seem to find anything wrong.

MODEL SIMULATION:

Warning: Matrix is singular to working precision.

In sim1_linear (line 199)
In perfect_foresight_solver_core (line 97)
In perfect_foresight_solver (line 63)
In Dynare_forum.driver (line 873)
In dynare (line 293)

## Iter: 1, Initial err. = 0.4515, err. = NaN, time = 0.046

Simulation terminated with NaN or Inf in the residuals or endogenous variables.
There is most likely something wrong with your model. Try model_diagnostics or another simulation method.

Here’s the .mod file

Dynare_forum.mod (11.8 KB)

Update: after debugging I seem to find the culprit, apparently Om (variable for measuring portfolio allocation between government bonds & loans among banks) has a derivative of 0. However, I do not understand why this is the case, and why this worked in a stochastic simulation but not a deterministic one

Simulation terminated with NaN or Inf in the residuals or endogenous variables.
There is most likely something wrong with your model. Try model_diagnostics or another simulation method.

Simulation of the perfect foresight model failed!Switching to a homotopy method…
Iter. | Lambda | status | Max. residual
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
The dynamic Jacobian is singular. The problem derives from:
The derivative with respect to the lag of Om being 0 for all equations.

Have a look at

``````(Rp) = (Rk)*(Om(-1))+(Rb)*(1-(Om(-1)));
``````

As `Rk=Rb`, this equation reduces to `Rp=Rk=Rb`. This is a problem for perfect foresight simulations as `Om(-1)` will drop out.

@jpfeifer Thank you Prof. I thought that was the problem as well. Although I am at a loss as to how to modify it, that equation determines the return on portfolio for banks and at steady state Rk must equal Rb

It seems the fundamental problem is the same one as at

Have a look at the attached file where I reduced the crazy tolerance you set, increased `periods` and substituted in for the Lagrange multiplier.
Dynare_forum.mod (11.9 KB)

Dear Professor, thank you so much for your help, it’s now working properly. You just single-handedly saved my thesis