I am working on a non-linear open economy model and as is usual in these frameworks the solution to the terms of trade cannot be obtained analytically. I followed the guidance of matlab and can solve for the variables of interest using fsolve. However, I tried to incorpotate it into the mod file, but the steady_state_model block doesn’t seem to recognise the command.

I attach my .m files that solve for the two relevant variables x(1) and x(2). The file nl_tot defines the function and the parameters, whereas nl_tot_sol obtains the solution. My question is - how do I incorporate these codes into a mod file? For example, if I just input the following:

var ...
varexo ...
parameters ...
...
model; ...
steady_state_model;
...
x0=[1 1];
xis=fsolve(@nl_tot,x0);
...
etc.

then dynare crashes as it does not recognise neither “” nor “@”. Should I use another file with @# operator to solve it?

One more question. For some reason, the external steady state file (which I copied from the NK_baseline example) is having some problems with loading the parameter values from the model. I haven’t changed the loops and they seem correct to me, but in the specification of the above ‘function’ command, both “ys” and “exo” are underlined in orange by matlab (which indicates that ys may not be used) unlike in the NK_baseline model.

To overcome this, I can simply copy and paste the values of my parameters into the _steadystate.m file, but then everytime I wish to change the parameter values, I need to do this twice. Needless to say, running loops with this approach would be problematic and inefficient. I would like to know what it is that I’m doing wrong.

I attach the results object (which loads the matrix M_ necessary to find the steady states) and the _steadystate.m file, which again works only with parameter values copied into the file (try deleting them and it will crash).

Thanks for the help.

P.S. the .mat file is too large for the forum, so you can download it from here: uploadfiles.io/c2e16. But the problem may be obvious from just looking at the _steadystate.m file for an experienced eye. tot_steadystate.m (11.7 KB)

Matlab will have problems in the steady state file whenever your parameters have the same name as built-in functions (which applies to probably all Greek letters). A workaround is to put a fake initialization before the first loop in the file, i.e.

[code]function[ys,check]=erpt_steadystate(ys,exo)
global M_

beta=0;
%% DO NOT CHANGE THIS PART.
%%
%% Here we load the values of the deep parameters in a loop.
%%
NumberOfParameters = M_.param_nbr; % Number of deep parameters.
for ii = 1:NumberOfParameters % Loop…
paramname = deblank(M_.param_names(ii,:)); % Get the name of parameter i.
eval( paramname ’ = M_.params(’ int2str(ii) ‘);’]); % Get the value of parameter i.
end % End of the loop.
check = 0;[/code]

That ys and exo are not used is correct. Tjere are applications where you might need them as inputs, but this is not the case here.