# Max() function

**URL:** <https://forum.dynare.org/t/max-function/915>\
**Category:** Dynare v4 (legacy)\
**Created:** [29 January 2009 22:55 UTC](https://forum.dynare.org/t/max-function/915 "2009-01-29T22:55:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sambler](https://forum.dynare.org/letter_avatar_proxy/v4/letter/s/34f0e0/32.png) [@sambler](https://forum.dynare.org/u/sambler)\
**Post date:** [29 January 2009 22:55 UTC](https://forum.dynare.org/t/max-function/915/1 "2009-01-29T22:55:21Z")

</div>

Hello,

I am trying to simulate a model w/ a Taylor rule for monetary policy and want to impose the zero lower bound. Looking through these forums, I see in the “pound lines again” thread that there is a max() function defined in Dynare 4 that takes 2 arguments. My code compiles without error but I still get values as small as about 0.985 for the gross nominal interest rate. I have a few questions.

1. Is the command documented anywhere?

2. Dynare needs to calculate derivatives of functions up to order 2. A max(1 , x) function has a kink at 1, so Dynare must approximate the function with a function that is differentiable at the kink. What is the functional form used? I know that there is a literature on nondifferentiable optimization, for example Israel Zang (1980), “A Smoothing-Out Technique for Min-Max Optimization” Mathematical Programming 19, 61-77. The technique suggested there is to define a smooth curve in the region of the kink only and splice it to the max() function at either endpoint, ensuring that the function never takes a value lower than the 1 in the example above, but Dynare can’t be using this technique.

3. Does the newest version of Dynare 4 allow for user-defined Matlab functions? I could easily write a Matlab script to reproduce the technique in the cited article, and run it to get the function into memory before invoking Dynare.

Thanks in advance.

Steve

---

<div class="post-metadata">

**Author:** ![sebastien](https://forum.dynare.org/user_avatar/forum.dynare.org/sebastien/32/19973_2.png) [@sebastien](https://forum.dynare.org/u/sebastien)\
**Post date:** [17 February 2009 10:20 UTC](https://forum.dynare.org/t/max-function/915/2 "2009-02-17T10:20:53Z")

</div>

Hi,

1. Unfortunately the command is not yet documented

2. Our way of computing the derivative of the max() function is not as clever as the one you suggest; basically, the derivative of “max(f(x), g(x)” is “(f(x)\>g(x))\*f’(x) + (f(x)\<=g(x))\*g’(x)”, where a comparison must be understood as evaluating to 1 or 0. So at the kink, by convention we give the derivative of the second argument, but this is clearly not satisfactory and is only meant as a convention.

Actually our max() function is principally meant for deterministic models where we don’t make local approximations; if you use a first or second order approximation (such as with stoch\_simul), you are basically replacing max(a,b) by whatever of the expressions is greater at the steady-state.

1. We should provide such a feature in the next major Dynare relase (probably numbered Dynare 4.1).

Best,

Sébastien

---

<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 July 2017 13:29 UTC](https://forum.dynare.org/t/max-function/915/3 "2017-07-24T13:29:01Z")

</div>



---

<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 July 2017 13:29 UTC](https://forum.dynare.org/t/max-function/915/4 "2017-07-24T13:29:44Z")

</div>


