# Minimizing negative welfare

**URL:** https://forum.dynare.org/t/minimizing-negative-welfare/3416
**Category:** Dynare help (legacy posts)
**Created:** [30 September 2013 16:41 UTC](https://forum.dynare.org/t/minimizing-negative-welfare/3416 "2013-09-30T16:41:54Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![bpyemba](https://forum.dynare.org/letter_avatar_proxy/v4/letter/b/e5b9ba/32.png) [@bpyemba](https://forum.dynare.org/u/bpyemba)
#### Post date: [30 September 2013 16:41 UTC](https://forum.dynare.org/t/minimizing-negative-welfare/3416/1 "2013-09-30T16:41:54Z")

</div>

I am getting that message when I am minimizing the negative welfare of the representative agent.

??? Reference to non-existent field ‘eigval’.

Error in ==\> check at 80  
eigenvalues\_ = dr.eigval;

Error in ==\> welfare4\_loop\_det at 333  
oo\_.dr.eigval = check(M\_,options\_,oo\_);

Error in ==\> cond\_welfare at 30  
welfare4\_loop\_det

Error in ==\> fminsearch at 265  
x(🙂 = y; f = funfcn(x,varargin{:});

Error in ==\> max\_cond\_welfare at 46  
[bigtheta\_star,condwelfare\_star] = fminsearch(‘cond\_welfare’,bigtheta\_start,options);

How can I solve the problem?

Thanks,

Boniface

---

<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: [30 September 2013 18:26 UTC](https://forum.dynare.org/t/minimizing-negative-welfare/3416/2 "2013-09-30T18:26:38Z")

</div>

Please post a mod-file documenting the issue and state the version of Dynare you are using.

---

<div class="post-metadata">

### Author: ![bpyemba](https://forum.dynare.org/letter_avatar_proxy/v4/letter/b/e5b9ba/32.png) [@bpyemba](https://forum.dynare.org/u/bpyemba)
#### Post date: [30 September 2013 19:03 UTC](https://forum.dynare.org/t/minimizing-negative-welfare/3416/3 "2013-09-30T19:03:06Z")

</div>

I am using the version 4.3.3\> Besides, the file is max\_cond\_welfare.

Here is the problem

> > max\_cond\_welfare

Configuring Dynare …  
[mex] Generalized QZ.  
[mex] Sylvester equation solution.  
[mex] Kronecker products.  
[mex] Sparse kronecker products.  
[mex] Local state space iteration (second order).  
[mex] Bytecode evaluation.  
[mex] k-order perturbation solver.  
[mex] k-order solution simulation.  
[mex] Quasi Monte-Carlo sequence (Sobol).  
[mex] Markov Switching SBVAR.

Starting Dynare (version 4.3.3).  
Starting preprocessing of the model file …  
Found 25 equation(s).  
Evaluating expressions…done  
Computing static model derivatives:

- order 1  
Computing dynamic model derivatives:
- order 1
- order 2  
Processing outputs …done  
Preprocessing completed.  
Starting MATLAB/Octave computing.

Total computing time : 0h00m04s

Configuring Dynare …  
[mex] Generalized QZ.  
[mex] Sylvester equation solution.  
[mex] Kronecker products.  
[mex] Sparse kronecker products.  
[mex] Local state space iteration (second order).  
[mex] Bytecode evaluation.  
[mex] k-order perturbation solver.  
[mex] k-order solution simulation.  
[mex] Quasi Monte-Carlo sequence (Sobol).  
[mex] Markov Switching SBVAR.

Starting Dynare (version 4.3.3).  
Starting preprocessing of the model file …  
Found 25 equation(s).  
Evaluating expressions…done  
Computing static model derivatives:

- order 1  
Computing dynamic model derivatives:
- order 1
- order 2  
Processing outputs …done  
Preprocessing completed.  
Starting MATLAB/Octave computing.

Total computing time : 0h00m04s  
Total computing time : 0h00m02s  
Total computing time : 0h00m02s

Iteration Func-count min f(x) Procedure  
0 1 -20.1585  
Total computing time : 0h00m01s  
Total computing time : 0h00m01s  
Total computing time : 0h00m01s  
Total computing time : 0h00m01s  
Total computing time : 0h00m01s  
Total computing time : 0h00m01s  
??? Reference to non-existent field ‘eigval’.

Error in ==\> check at 80  
eigenvalues\_ = dr.eigval;

Error in ==\> welfare4\_loop\_det at 333  
oo\_.dr.eigval = check(M\_,options\_,oo\_);

Error in ==\> cond\_welfare at 30  
welfare4\_loop\_det

Error in ==\> fminsearch at 265  
x(🙂 = y; f = funfcn(x,varargin{:});

Error in ==\> max\_cond\_welfare at 46  
[bigtheta\_star,condwelfare\_star] = fminsearch(‘cond\_welfare’,bigtheta\_start,options);  
[boniface.zip](https://forum.dynare.org/uploads/default/original/2X/d/d1e893bbcb628cc766d0f5489bc176330171dd11.zip) (4.75 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: [30 September 2013 19:27 UTC](https://forum.dynare.org/t/minimizing-negative-welfare/3416/4 "2013-09-30T19:27:28Z")

</div>

Try following the steps outlined here:  
[[Loop over parameters](http://forum.dynare.org/t/loop-over-parameters/3335/1))  
to program a more efficient loop.  
The issue seems to be that you do not allow for stoch\_simul to fail, e.g. due to Blanchard-Kahn violations. In this case, the eigenvalues will not be computed/stored. At the previous link, you will see that

```auto
info=stoch_simul(var_list_)
```

is called. Here, info stores the exit code of stoch\_simul. If it is 0, everything is fine. If info\>0, the solution could not be computed and you need to attach a penalty for this outcome to deal with your optimizer.

---

<div class="post-metadata">

### Author: ![bpyemba](https://forum.dynare.org/letter_avatar_proxy/v4/letter/b/e5b9ba/32.png) [@bpyemba](https://forum.dynare.org/u/bpyemba)
#### Post date: [30 September 2013 20:16 UTC](https://forum.dynare.org/t/minimizing-negative-welfare/3416/5 "2013-09-30T20:16:29Z")

</div>

Thanks.

Boniface
