# \`optim\` undocumented \`err\` values?

**URL:** <https://scilab.discourse.group/t/optim-undocumented-err-values/979>\
**Category:** Optimization\
**Created:** [June 19, 2025, 9:10am UTC](https://scilab.discourse.group/t/optim-undocumented-err-values/979 "2025-06-19T09:10:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nilrua](https://avatars.discourse-cdn.com/v4/letter/n/5f9b8f/32.png) [@nilrua](https://scilab.discourse.group/u/nilrua)\
**Post date:** [June 19, 2025, 9:10am UTC](https://scilab.discourse.group/t/optim-undocumented-err-values/979/1 "2025-06-19T09:10:48Z")

</div>

Hello everyone,

when I use `optim` and retrieve the `err` flag, I got values of 12 and 13, about which I didn’t find any information. From the documentation, I have this:

err=1: Norm of projected gradient lower than…  
err=2: At last iteration f decreases by less than…  
err=3: Optimization stops because of too small variations for x.  
err=4: Optim stops: maximum number of calls to f is reached.  
err=5: Optim stops: maximum number of iterations is reached.  
err=6: Optim stops: too small variations in gradient direction.  
err=7: Stop during calculation of descent direction.  
err=8: Stop during calculation of estimated hessian.  
err=9: End of optimization, successful completion.  
err=10: End of optimization (linear search fails).

Please find below a truncated example of console output with the `iprint` flag set to 2 and a returned value of 12.

```auto
 ***********qnbd (with bound cstr)****************
dimension= 4, epsq= 0.2220446049250313E-15, verbosity level: iprint= 2
max number of iterations allowed: iter= 100
max number of calls to costf allowed: nap= 100
------------------------------------------------
 qnbd : iter= 1 f= 0.1126653D-01
 qnbd : nbre fact 4 defact 0 total var factorisees 4
 qnbd : epsg,difg= 0.2220D-15 0.2162D-01 epsf,diff= 0.0000D+00 0.4108D-02 nap= 8
 qnbd : iter= 2 f= 0.7158237D-02
 qnbd : nbre fact 0 defact 0 total var factorisees 4
 qnbd : epsg,difg= 0.2220D-15 0.1146D-01 epsf,diff= 0.0000D+00 0.7266D-03 nap= 10
...
...
 qnbd : nbre fact 0 defact 0 total var factorisees 4
 qnbd : epsg,difg= 0.2220D-15 0.1818D-03 epsf,diff= 0.0000D+00 0.1151D-08 nap= 33
 qnbd : iter= 21 f= 0.5656227D-02
 qnbd : nbre fact 0 defact 0 total var factorisees 4
 qnbd : epsg,difg= 0.2220D-15 0.1818D-03 epsf,diff= 0.0000D+00 0.8674D-18 nap= 48
 qnbd : iter= 22 f= 0.5656227D-02
 qnbd : nbre fact 0 defact 0 total var factorisees 4
 qnbd : indqn= 12

```

I tried searching in the source code, but I am not familiar with it and didn’t find anything relevant.

Does anyone know what the `err` values of 12 and 13 mean?

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [June 19, 2025, 11:48am UTC](https://scilab.discourse.group/t/optim-undocumented-err-values/979/2 "2025-06-19T11:48:31Z")

</div>

Hello, welcome to Scilab’s Discourse !

after looking into the sources (see [scilab/modules/optimization/src/fortran/zqnbd.f · main · scilab / scilab · GitLab](https://gitlab.com/scilab/scilab/-/blob/main/scilab/modules/optimization/src/fortran/zqnbd.f?ref_type=heads) and [scilab/modules/optimization/src/fortran/rlbd.f · main · scilab / scilab · GitLab](https://gitlab.com/scilab/scilab/-/blob/main/scilab/modules/optimization/src/fortran/rlbd.f?ref_type=heads)), indqn=12 means that the linear search failed because of a too small step increment and indqn=13 that the maximum number of calls to the user function (cost+gradient) has been exceeded. I do agree that these values should be mapped to err=10 and err=4, respectively.

S.

---

<div class="post-metadata">

**Author:** ![nilrua](https://avatars.discourse-cdn.com/v4/letter/n/5f9b8f/32.png) [@nilrua](https://scilab.discourse.group/u/nilrua)\
**Post date:** [June 19, 2025, 12:26pm UTC](https://scilab.discourse.group/t/optim-undocumented-err-values/979/3 "2025-06-19T12:26:30Z")

</div>

Thanks a lot Stéphane !
