# Unable to solve model

**URL:** https://forum.dynare.org/t/unable-to-solve-model/19284
**Category:** Steady state
**Created:** [13 November 2021 16:02 UTC](https://forum.dynare.org/t/unable-to-solve-model/19284 "2021-11-13T16:02:30Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![steve\_1983](https://forum.dynare.org/letter_avatar_proxy/v4/letter/s/71e660/32.png) [@steve\_1983](https://forum.dynare.org/u/steve_1983)
#### Post date: [13 November 2021 16:02 UTC](https://forum.dynare.org/t/unable-to-solve-model/19284/1 "2021-11-13T16:02:30Z")

</div>

Attached is a mod file. I am getting some weird residual values. Can someone figure out what is missing here.

[mutualfunds.mod](https://forum.dynare.org/uploads/short-url/dba6uwFjJaiVaeL59bG3RpVgXbl.mod) (3.3 KB)

---

<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: [13 November 2021 19:58 UTC](https://forum.dynare.org/t/unable-to-solve-model/19284/2 "2021-11-13T19:58:11Z")

</div>

Try computing the steady state analytically.

---

<div class="post-metadata">

### Author: ![steve\_1983](https://forum.dynare.org/letter_avatar_proxy/v4/letter/s/71e660/32.png) [@steve\_1983](https://forum.dynare.org/u/steve_1983)
#### Post date: [14 November 2021 01:36 UTC](https://forum.dynare.org/t/unable-to-solve-model/19284/3 "2021-11-14T01:36:53Z")

</div>

I have computed steady state analytically

---

<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: [14 November 2021 20:00 UTC](https://forum.dynare.org/t/unable-to-solve-model/19284/4 "2021-11-14T20:00:19Z")

</div>

Then

> [@Nonzero residuals of static equations](https://forum.dynare.org/t/nonzero-residuals-of-static-equations/15442/11):
>
> Option ii). Your entered equations and the computed steady state values are inconsistent. There must be a mistake somewhere, but it is unclear whether it is the model equations or the steady state computation that has the mistake.

applies

---

<div class="post-metadata">

### Author: ![steve\_1983](https://forum.dynare.org/letter_avatar_proxy/v4/letter/s/71e660/32.png) [@steve\_1983](https://forum.dynare.org/u/steve_1983)
#### Post date: [16 November 2021 17:28 UTC](https://forum.dynare.org/t/unable-to-solve-model/19284/5 "2021-11-16T17:28:54Z")

</div>

Unable to understand why I am suddenly getting Nan. Steady state has been calculated analytically and appears and initial values. Its a simple model which is behaving weird. Can someone help figure out.[mutualfunds\_v2.mod](https://forum.dynare.org/uploads/short-url/bjX24MJm0TPF7X7c7DflF3ESrjD.mod) (3.6 KB)

---

<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: [17 November 2021 11:34 UTC](https://forum.dynare.org/t/unable-to-solve-model/19284/6 "2021-11-17T11:34:32Z")

</div>

You are setting

```auto
o_f = of_bar;

```

but did not set `of_bar`. So both will be 0, resulting in a division by 0.

---

<div class="post-metadata">

### Author: ![steve\_1983](https://forum.dynare.org/letter_avatar_proxy/v4/letter/s/71e660/32.png) [@steve\_1983](https://forum.dynare.org/u/steve_1983)
#### Post date: [21 November 2021 12:49 UTC](https://forum.dynare.org/t/unable-to-solve-model/19284/7 "2021-11-21T12:49:54Z")

</div>

I am trying to minimise a loss function subject to am optimal simple rule. But I find that although dynare is throwing estimates of the parameters, the value of the objective function is not changing. Can someone figure out what is the reason for this? I have tried with different initial values also, but objective function does not change from where it started. here are the results I am getting

OSR: Initial value of the objective function: 0.0336506

n=5: (4,8)-CMA-ES(w=[53 29 14 4]%, mu\_eff=2.6) on function osr\_obj  
Iterat, #Fevals: Function Value (median,worst) |Axis Ratio|idx:Min SD idx:Max SD  
1 , 9 : 3.3650636293349e-02 +(3e-12,6e-12) | 1.99e+01 | 2:9.4e-03 1:1.9e-01  
2 , 17 : 3.3650636294518e-02 +(1e-12,3e-12) | 2.00e+01 | 2:9.1e-03 1:1.8e-01  
3 , 25 : 3.3650636295258e-02 +(2e-12,7e-12) | 2.00e+01 | 2:9.4e-03 1:1.8e-01  
#Fevals: f(returned x) | bestever.f | stopflag (saved to variablescmaes.mat)  
26: 3.36506362953e-02 | 3.36506362933e-02 | tolfun  
mean solution: +4.7e-01 +4.9e-01 +5.2e-01 +5.1e-01 +5.2e-01  
std deviation: 1.8e-01 9.4e-03 1.0e-02 1.1e-02 1.1e-02  
use plotcmaesdat.m for plotting the output at any time (option LogModulo must not be zero)

OPTIMAL VALUE OF THE PARAMETERS:

```
  gamma 0.49405

  g1 0.498351

  g2 0.506277

  g3 0.510933

  g4 0.511093

```

Objective function : 0.0336506[mutualfunds\_v3WithLabor.mod](https://forum.dynare.org/uploads/short-url/oExibYDnyn1WHAUMWpvnKcTs4Uy.mod) (4.5 KB)

---

<div class="post-metadata">

### Author: ![steve\_1983](https://forum.dynare.org/letter_avatar_proxy/v4/letter/s/71e660/32.png) [@steve\_1983](https://forum.dynare.org/u/steve_1983)
#### Post date: [22 November 2021 15:38 UTC](https://forum.dynare.org/t/unable-to-solve-model/19284/8 "2021-11-22T15:38:13Z")

</div>

What does the objective function value indicate? Is this the value of the loss function?

---

<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: [22 November 2021 18:42 UTC](https://forum.dynare.org/t/unable-to-solve-model/19284/9 "2021-11-22T18:42:21Z")

</div>

Yes, this value is a loss function. Have tried whether the respective variances are sensitive to the parameters you are optimizing over?

---

<div class="post-metadata">

### Author: ![steve\_1983](https://forum.dynare.org/letter_avatar_proxy/v4/letter/s/71e660/32.png) [@steve\_1983](https://forum.dynare.org/u/steve_1983)
#### Post date: [22 November 2021 19:00 UTC](https://forum.dynare.org/t/unable-to-solve-model/19284/10 "2021-11-22T19:00:24Z")

</div>

@jpfeifer. Thanks for looking at the problem. I used your code

% make loop silent  
options\_.nofunctions=1;  
options\_.nocorr=1;  
options\_.noprint=1;  
options\_.irf=0;  
options\_.silent\_optimizer=1;

options\_.osr.opt\_algo=9;

% find position of variables in variable\_weights  
y\_pos=strmatch(‘y\_hat’,M\_.endo\_names,‘exact’);  
pi\_pos=strmatch(‘pi\_hat’,M\_.endo\_names,‘exact’);

% find position of variables in var\_list\_  
y\_pos\_var\_list\_=strmatch(‘y\_hat’,var\_list\_,‘exact’);  
pi\_pos\_var\_list\_=strmatch(‘pi\_hat’,var\_list\_,‘exact’);

weight\_grid=0:0.01:1;  
n\_grid\_points=length(weight\_grid);  
var\_y=NaN(n\_grid\_points,1);  
var\_pi=NaN(n\_grid\_points,1);  
for grid\_iter=1:n\_grid\_points  
M\_.osr.variable\_weights(pi\_pos,pi\_pos) = weight\_grid(grid\_iter);  
M\_.osr.variable\_weights(y\_pos,y\_pos) = (1-weight\_grid(grid\_iter));  
oo\_.osr = osr(var\_list\_,M\_.osr.param\_names,M\_.osr.variable\_indices,M\_.osr.variable\_weights);  
if oo\_.osr.error\_indicator==0  
var\_y(grid\_iter)=oo\_.var(y\_pos\_var\_list\_,y\_pos\_var\_list\_);  
var\_pi(grid\_iter)=oo\_.var(pi\_pos\_var\_list\_,pi\_pos\_var\_list\_);  
end  
end  
figure  
plot(var\_y,var\_pi)

after my standard code

I am getting this error

ERROR: mf\_frontier.mod: line 257, cols 8-10: syntax error, unexpected NAME, expecting EQUAL or ‘.’  
I am attaching the mod file. Can you please let me know where the problem lies. Should this code be used in the mod file or elsewhere.  
[mf\_frontier.mod](https://forum.dynare.org/uploads/short-url/yYWjfAZPU0Q88wiLGpbQY2LScZ9.mod) (5.7 KB)

---

<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: [23 November 2021 11:38 UTC](https://forum.dynare.org/t/unable-to-solve-model/19284/11 "2021-11-23T11:38:44Z")

</div>

Use

```auto
% find position of variables in variable_weights
y_pos=strmatch('y',M_.endo_names,'exact');
pi_pos=strmatch('pi',M_.endo_names,'exact');

verbatim;
% % find position of variables in var_list_
if ~isempty(var_list_)
    y_pos_var_list_=strmatch('y',var_list_,'exact');
    pi_pos_var_list_=strmatch('pi',var_list_,'exact');
else
    y_pos_var_list_=y_pos;
    pi_pos_var_list_=pi_pos;    
end
weight_grid=0:0.01:1;
n_grid_points=length(weight_grid);
var_y=NaN(n_grid_points,1);
var_pi=NaN(n_grid_points,1);
for grid_iter=1:n_grid_points
    M_.osr.variable_weights(pi_pos,pi_pos) = weight_grid(grid_iter);
    M_.osr.variable_weights(y_pos,y_pos) = (1-weight_grid(grid_iter));
    oo_.osr = osr(var_list_,M_.osr.param_names,M_.osr.variable_indices,M_.osr.variable_weights);
    if oo_.osr.error_indicator==0
        var_y(grid_iter)=oo_.var(y_pos_var_list_,y_pos_var_list_);
        var_pi(grid_iter)=oo_.var(pi_pos_var_list_,pi_pos_var_list_);
    end
end
end;
figure
plot(var_y,var_pi)

```

---

<div class="post-metadata">

### Author: ![steve\_1983](https://forum.dynare.org/letter_avatar_proxy/v4/letter/s/71e660/32.png) [@steve\_1983](https://forum.dynare.org/u/steve_1983)
#### Post date: [23 November 2021 16:40 UTC](https://forum.dynare.org/t/unable-to-solve-model/19284/12 "2021-11-23T16:40:39Z")

</div>

@jpfeifer I am not sure what this code is doing. Previous posts suggest that it finds the optimal coefficients of the loss function. But in my case, there is no change in the coefficients. Am I missing something here. Here is my mod file.  
[mf\_frontier.mod](https://forum.dynare.org/uploads/short-url/14W9klf3jX4rYpEPfpXkFMiqwXp.mod) (5.8 KB)

---

<div class="post-metadata">

### Author: ![Max1](https://forum.dynare.org/letter_avatar_proxy/v4/letter/m/e99b99/32.png) [@Max1](https://forum.dynare.org/u/Max1)
#### Post date: [23 November 2021 17:23 UTC](https://forum.dynare.org/t/unable-to-solve-model/19284/13 "2021-11-23T17:23:39Z")

</div>

Your code is computing a so-called Taylor curve.  
It changes the weight of output vs. inflation in the objective function, computes the OSR coefficients minimizing the objective for each weighting scheme and plots the resulting policy frontier/Taylor curve by drawing the output-inflation variance trade-off.

---

<div class="post-metadata">

### Author: ![steve\_1983](https://forum.dynare.org/letter_avatar_proxy/v4/letter/s/71e660/32.png) [@steve\_1983](https://forum.dynare.org/u/steve_1983)
#### Post date: [24 November 2021 06:43 UTC](https://forum.dynare.org/t/unable-to-solve-model/19284/14 "2021-11-24T06:43:09Z")

</div>

But the problem is the values(weights) of the coefficients of the objective function are not changing at all. They are fixed at the initial values.

---

<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: [24 November 2021 14:39 UTC](https://forum.dynare.org/t/unable-to-solve-model/19284/15 "2021-11-24T14:39:13Z")

</div>

That’s not true:

```auto
    M_.osr.variable_weights(pi_pos,pi_pos) = weight_grid(grid_iter);
    M_.osr.variable_weights(y_pos,y_pos) = (1-weight_grid(grid_iter));

```

changes the weights

---

<div class="post-metadata">

### Author: ![benettonb1](https://forum.dynare.org/letter_avatar_proxy/v4/letter/b/ccd318/32.png) [@benettonb1](https://forum.dynare.org/u/benettonb1)
#### Post date: [25 November 2021 08:58 UTC](https://forum.dynare.org/t/unable-to-solve-model/19284/16 "2021-11-25T08:58:49Z")

</div>

i got same problem

---

<div class="post-metadata">

### Author: ![steve\_1983](https://forum.dynare.org/letter_avatar_proxy/v4/letter/s/71e660/32.png) [@steve\_1983](https://forum.dynare.org/u/steve_1983)
#### Post date: [25 November 2021 17:01 UTC](https://forum.dynare.org/t/unable-to-solve-model/19284/17 "2021-11-25T17:01:21Z")

</div>

@jpfeifer No my initial value was beta3=0.7 and it remains 0.7 after the iteration. There is no change in values.

[mf\_frontier.mod](https://forum.dynare.org/uploads/short-url/74XtoC9rnINNWDnTf72KpN0hdh6.mod) (5.8 KB)

---

<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: [26 November 2021 11:50 UTC](https://forum.dynare.org/t/unable-to-solve-model/19284/18 "2021-11-26T11:50:56Z")

</div>

> [@steve\_1983](#):
>
> @jpfeifer No my initial value was beta3=0.7 and it remains 0.7 after the iteration. There is no change in values.

You did not tell us what you are trying to do in the first place. The loop does not even try to change `beta3`.

---

<div class="post-metadata">

### Author: ![benettonb1](https://forum.dynare.org/letter_avatar_proxy/v4/letter/b/ccd318/32.png) [@benettonb1](https://forum.dynare.org/u/benettonb1)
#### Post date: [7 December 2021 08:43 UTC](https://forum.dynare.org/t/unable-to-solve-model/19284/19 "2021-12-07T08:43:57Z")

</div>

same problem[.](https://spicemoneylogin.in)[.](https://myfiosgateway.one)
