• To: mathgroup at smc.vnet.net
• Subject: [mg24043] RE: [mg24006] Gradient in FindMininum
• From: "David Park" <djmp at earthlink.net>
• Date: Wed, 21 Jun 2000 02:20:03 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```
> -----Original Message-----
> From: Johannes Ludsteck [mailto:ludsteck at zew.de]
To: mathgroup at smc.vnet.net

> Dear MathGroup Members,
> Unfortunately I got no answer when I sent the question below last
> week to the mathgroup mailing list. Since I think that the problem
> is not a very special one but a general problem of the way how
> Mathematica treats numerical integrals in the computation of
> I want to minimize a complicated function which contains
> numerical integrals. Since the function is too complicated for a
> direct demonstration, I give a simple example which makes the
> structure of the problem clear:
>
> The (example) function to be minimized is:
> f[x_] := NIntegrate[g[t], {t, -Infinity, x}]
>
> (g is a known function; however symbolical integration is
> impossible).
>
> When I request numerical minimization of this function by typing
>
> FindMinimum[f[x],{x,1}]
>
> Mathematica gives me the following error message:
>
> FindMinimum::fmgl: Gradient {Indeterminate} is not a length 1
> list of real numbers at {x} = {1.}.
>
> Appearently, Mathematica is not able to find the gradient
> symbolically. A simple solution would be to define f using Integrate
> (without prefix N) and to wrap it with N[ ]:
>
> f[x_]:= N[  Integrate[g[t], {t,-Infinity, x}] ]
>
> However, since the function contains some hundred terms,
> evaluation of the function takes several minutes. (Mathematica then
> tries to find the integral symbolically before applying the numerical
> integration procedure.) This makes optimization impracticable.
> (the function I want to optimize has about 40 variables!).
>
> Are there any suggestions how to avoid computation of the gradient
> manually? (minimization algorithms which don't use the gradient
> are impracticable.)
> I.e. how can I tell Mathematica to use the first definition
>
> f[x_] := NIntegrate[g[t], {t, -Infinity, x}]
>
> for evaluation of the function and the second
>
> f[x_]:= N[ Integrate[g[t], {t,-Infinity, x}] ]
>
> for the computation of the gradient.
>
> Thank you
>
> P.S If you want to reproduce the error message, you can use a
> simple definition:
>
> f[x_]:= x^2 + NIntegrate[ Exp[-t^2], {t, -Infinity, x} ].
>
>
>
>
> Johannes Ludsteck
> Centre for European Economic Research (ZEW)

Johannes,

Well, I not an expert on this, but since you received no previous answers,
and I was able to find out something, I will post it.

I think you have to use the proper form of FindMinimum (two starting points)
when Mathematica can't calculate a symbolic derivative. For your simple
example:

f[x_] := x^2 + NIntegrate[ Exp[-t^2], {t, -Infinity, x} ]

FindMinimum[f[x], {x, {1, 1.1}}]
{0.666069, {x -> -0.419365}}

Plot[f[x], {x, -3, 3}]; checks the solution.

Or if your are going to do a lot of calculations on the function, you might
consider calculating an InterpolationFunction approximation once and for
all, and then using it in subsequent operations. Of course, you lose a
little accuracy.

fi = Interpolation[Table[{x, f[x]}, {x, -3, 3, 0.1}]]
InterpolatingFunction[{{-3., 3.}}, "<>"]

FindMinimum[fi[x], {x, {1, 2}}]
{0.666074, {x -> -0.419282}}

and even this form works...

FindMinimum[fi[x], {x, 1}]
{0.666074, {x -> -0.419282}}

David Park