# Incorporating matlab function into dynare

**URL:** <https://forum.dynare.org/t/incorporating-matlab-function-into-dynare/4066>\
**Category:** Dynare help (legacy posts)\
**Created:** [30 July 2014 22:59 UTC](https://forum.dynare.org/t/incorporating-matlab-function-into-dynare/4066 "2014-07-30T22:59:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![diatrochoi](https://forum.dynare.org/letter_avatar_proxy/v4/letter/d/58956e/32.png) [@diatrochoi](https://forum.dynare.org/u/diatrochoi)\
**Post date:** [30 July 2014 22:59 UTC](https://forum.dynare.org/t/incorporating-matlab-function-into-dynare/4066/1 "2014-07-30T22:59:52Z")

</div>

Hi

I’m trying to use matlab to solve for the steady state and then use those steady state values as initial value in the dynare file.

My model\_steadystate.m is as exactly as follows:

syms x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13  
h=solve(EQ1,EQ2…EQ13)  
c1=h.x1(1)  
c2=h.x2(1)  
…  
G=h.x13(1)

The corresponding part in my model.mod file is as follows:  
model;  
…  
end;  
model\_steadstate.m; //the parameter values are passed from .mod to .m file from here I believe  
initval;  
c1=h.x1(1)  
c2=h.x2(1)  
…  
G=h.x13(1)  
end;

steady;  
check;

However, I get “ERROR: model.mod: line 69, col 5: character unrecognized by lexer” (line 69 is the line c1=h.x1(1) in the dynare file) when I run the dynare file. How should I correct this? Is it because I’m not calling the .m file from the .mod file correctly?

Thanks

---

<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:** [31 July 2014 07:36 UTC](https://forum.dynare.org/t/incorporating-matlab-function-into-dynare/4066/2 "2014-07-31T07:36:24Z")

</div>

To cut the long story short: if you have a file to compute the steady state values, do not use initval, but write a full-fledged steady state file. An example is in Dynare 4.4.2 for the NK\_baseline.mod. You just need to copy your steady state computation file in between the header and footer of that file and rename the file according to the naming conventions.

---

<div class="post-metadata">

**Author:** ![diatrochoi](https://forum.dynare.org/letter_avatar_proxy/v4/letter/d/58956e/32.png) [@diatrochoi](https://forum.dynare.org/u/diatrochoi)\
**Post date:** [31 July 2014 18:29 UTC](https://forum.dynare.org/t/incorporating-matlab-function-into-dynare/4066/3 "2014-07-31T18:29:37Z")

</div>

I got it to run. But everytime the steady state file crash, the whole process is terminated. Im testing the model with 4 loops for 4 parameters. Is it possible to make it such that if 1 set of parameter values causes crash, the program moves on with the next set rather than terminating? (Im using to solve() function of matlab for my steady state file)

Thanks

---

<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 August 2014 05:56 UTC](https://forum.dynare.org/t/incorporating-matlab-function-into-dynare/4066/4 "2014-08-01T05:56:40Z")

</div>

Set noprint in stoch\_simul to 1 to prevent Dynare crashing on errors. stoch\_simul will then return an error code in info that can be used in an if-clause: [[Loop over parameters](https://forum.dynare.org/t/loop-over-parameters/3335/1))
