# Homotopy approach in Deterministic Simulation

**URL:** <https://forum.dynare.org/t/homotopy-approach-in-deterministic-simulation/19204>\
**Category:** Manual\
**Created:** [29 October 2021 14:03 UTC](https://forum.dynare.org/t/homotopy-approach-in-deterministic-simulation/19204 "2021-10-29T14:03:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex.crescentini](https://forum.dynare.org/user_avatar/forum.dynare.org/alex.crescentini/32/18322_2.png) [@alex.crescentini](https://forum.dynare.org/u/alex.crescentini)\
**Post date:** [29 October 2021 14:03 UTC](https://forum.dynare.org/t/homotopy-approach-in-deterministic-simulation/19204/1 "2021-10-29T14:03:30Z")

</div>

Hello everyone,

I’m wondering if there is a way to directly compute a deterministic simulation with the perfect foresight solver using the homotopy approach. The manual explains that when Dynare fails to compute the simulation it switches to the homotopy approach and that we can freeze this option using no homotopy command. However, nothing is said about using the homotopy approach directly without waiting for Dynare’s iterations which I already know will fail.

Thank you.

Alex Crescentini.

---

<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:** [1 November 2021 14:44 UTC](https://forum.dynare.org/t/homotopy-approach-in-deterministic-simulation/19204/2 "2021-11-01T14:44:57Z")

</div>

No, that is not feasible, but you could hack the `perfect_foresight_solver` to get that behavior if really needed.

---

<div class="post-metadata">

**Author:** ![alex.crescentini](https://forum.dynare.org/user_avatar/forum.dynare.org/alex.crescentini/32/18322_2.png) [@alex.crescentini](https://forum.dynare.org/u/alex.crescentini)\
**Post date:** [2 November 2021 07:21 UTC](https://forum.dynare.org/t/homotopy-approach-in-deterministic-simulation/19204/3 "2021-11-02T07:21:19Z")

</div>

I need that just because there’s a little mistake in the dynamic of my model. Therefore, I need to do some trials and that command for sure will allow me to be faster instead of waiting each time for all the default iterations. Do you have some hints on how to hack the solver?

---

<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:** [2 November 2021 07:31 UTC](https://forum.dynare.org/t/homotopy-approach-in-deterministic-simulation/19204/4 "2021-11-02T07:31:49Z")

</div>

In `perfect_foresight_solver.m` around line 63 there is the part

```auto
oo_ = perfect_foresight_solver_core(M_,options_,oo_);

% If simulation failed try homotopy.
if ~oo_.deterministic_simulation.status && ~options_.no_homotopy

```

Instead of calling the solver with

```auto
oo_ = perfect_foresight_solver_core(M_,options_,oo_);

```

replace it by the outcome that the solution failed:

```auto
oo_.deterministic_simulation.status=0

```

---

<div class="post-metadata">

**Author:** ![alex.crescentini](https://forum.dynare.org/user_avatar/forum.dynare.org/alex.crescentini/32/18322_2.png) [@alex.crescentini](https://forum.dynare.org/u/alex.crescentini)\
**Post date:** [2 November 2021 08:17 UTC](https://forum.dynare.org/t/homotopy-approach-in-deterministic-simulation/19204/5 "2021-11-02T08:17:32Z")

</div>

It worked. You helped me a lot.

Thank you, Johannes.
