[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: Maximize a function that contains an integral

From   "Feiveson, Alan H. (JSC-SK311)" <>
To   "" <>
Subject   st: RE: Maximize a function that contains an integral
Date   Tue, 3 Mar 2009 16:30:21 -0600

Bob - Try looking at 

Al Feiveson

-----Original Message-----
From: [] On Behalf Of Bob Hammond
Sent: Tuesday, March 03, 2009 4:24 PM
Subject: st: Maximize a function that contains an integral


I want to find the maximum of a function that contains an integral without an analytical solution.  The difficulty is that the argument of the maximization is the lower bound of the integral.  Consider the following trivial example: find the x that maximizes f(x), where f(x) is the integral of z (with respect to z) from a lower bound of x to an upper bound of 0.  Computing the integral by hand shows that x* = 0 (because f(x) = -0.5x^2) but I would like to know how to code this without invoking the analytical solution.

Note that I cannot simply differentiate f(x) with respect to x and use a root finder (e.g., mm_root) to find the optimum because my f'(x) also contains an integral.

I've used Stata's integ command to great effect in similar applications but do not know how to embed it into my problem of maximizing f(x).  It occurred to me that I could use ml instead of Mata but I'm not sure how that would be done since the argument of the optimization problem is the lower bound of the integration. 

The most promising approach that I've found seems to be "Quadrature on sparse grids":

which contains a Mata function nwspgr() in a zip file.  I've spent some time with this function and it's very accurate but I cannot figure out how to manipulate the integration bounds such that the lower bound is a variable that I can feed in from an optimizer such as Mata's optimize.

I will contact the authors of nwspgr() but I wanted to check a few things before doing so:

1. Is there an existing Mata equivalent to integ (which easily allows manipulation of the integration bounds)?
2. Relative to using Mata and (possibly) nwspgr(), would it be simpler to use integ and ml?  If so, I would appreciate any tips.


Bob Hammond
Department of Economics
North Carolina State University
Office: (919) 513-2871
Fax: (919) 515-7873
*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2021 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index