# The deterministic case fails but the stochastic case is OK

**URL:** <https://forum.dynare.org/t/the-deterministic-case-fails-but-the-stochastic-case-is-ok/18787>\
**Category:** Perfect foresight simulations\
**Created:** [26 August 2021 13:19 UTC](https://forum.dynare.org/t/the-deterministic-case-fails-but-the-stochastic-case-is-ok/18787 "2021-08-26T13:19:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fuyangzhao](https://forum.dynare.org/letter_avatar_proxy/v4/letter/f/41988e/32.png) [@fuyangzhao](https://forum.dynare.org/u/fuyangzhao)\
**Post date:** [26 August 2021 13:19 UTC](https://forum.dynare.org/t/the-deterministic-case-fails-but-the-stochastic-case-is-ok/18787/1 "2021-08-26T13:19:25Z")

</div>

Dear Prof Pfeifer,

I’m trying to simulate a simple model under deterministic case. The model is small. The steady state is easy to solve. BK condition is satisfied. And the stochastic simulation works fine.

However, the perfect foresight simulation always fails. It seem that there is a singular Jacobian problem…  
I have read the link [https://forum.dynare.org/t/perfect-foresight-simulation-always-failed/17651/2](https://forum.dynare.org/t/perfect-foresight-simulation-always-failed/17651/2). But there is no similar problem in my mod file.  
Any clue how I can solve it? Thank you in advance!

---

<div class="post-metadata">

**Author:** ![fuyangzhao](https://forum.dynare.org/letter_avatar_proxy/v4/letter/f/41988e/32.png) [@fuyangzhao](https://forum.dynare.org/u/fuyangzhao)\
**Post date:** [26 August 2021 13:22 UTC](https://forum.dynare.org/t/the-deterministic-case-fails-but-the-stochastic-case-is-ok/18787/2 "2021-08-26T13:22:21Z")

</div>

I provide my mod and m files in the attachment  
[attachfile.zip](https://forum.dynare.org/uploads/short-url/wxJFf2mVV6rAk3usOPzbSBEew6.zip) (105.5 KB)  
The zip file includes both deterministic case and stochastic case. And run “Main\_RunMe.m”, you can see the results

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [29 August 2021 16:00 UTC](https://forum.dynare.org/t/the-deterministic-case-fails-but-the-stochastic-case-is-ok/18787/3 "2021-08-29T16:00:08Z")

</div>

Using

```auto
perfect_foresight_setup(periods=100); 
perfect_foresight_solver(stack_solve_algo=0,robust_lin_solve);

```

found a solution.
