Find the minimum of the function defined by integration in Mathematica

I need to find the minimum of the function f (t) = int g (t, x) dx over [0,1]. What I did in math is as follows:

f[t_] = NIntegrate[g[t,x],{x,-1,1}]
FindMinimum[f[t],{t,t0}]

However, the math stops on the first try, since NIntegrate does not work with symbolic t. Evaluation requires a specific value. Although Plot [f [t], {t, 0,1}] works perferctly, FindMinimum stops at the starting point.

I cannot replace NIntegrate with Integrate because the function g is a little complicated, and if you type Integrate, the math just keeps working ...

How to get around this? Thank!

+5
source share
3 answers

Try the following:

In[58]:= g[t_, x_] := t^3 - t + x^2

In[59]:= f[t_?NumericQ] := NIntegrate[g[t, x], {x, -1, 1}]

In[60]:= FindMinimum[f[t], {t, 1}]

Out[60]= {-0.103134, {t -> 0.57735}}

In[61]:= Plot[f[t], {t, 0, 1}]

Two relevant changes I have made to your code:

  • f := =. f "later", f . . SetDelayed.

  • f t_?NumericQ t_. , t (Pi, 7, 0 ..). (t, x, "foo" ..).

+10

...

, Mathematica g [t, x] w.r.t x, w.r.t. . g [t, x], x t:

g[t_, x_] := t^2 + (7*t*x - (x^3)/13)^2;
xMax = 1; xMin = -1; f[t_?NumericQ] := NIntegrate[g[t, x], {x, xMin, xMax}];
tMin = 0; tMax = 1;Plot[f[t], {t, tMin, tMax}];
tNumericAtMin = t /. FindMinimum[f[t], {t, tMax}][[2]];
dig[t_, x_] := D[Integrate[g[t, x], x], t];
Print["Differentiated integral is ", dig[t, x]];
digAtXMax = dig[t, x] /. x -> xMax; digAtXMin = dig[t, x] /. x -> xMin;
tSymbolicAtMin = Resolve[digAtXMax - digAtXMin == 0 && tMin ≤ t ≤ tMax, {t}];
Print["Exact: ", tSymbolicAtMin[[2]]];
Print["Numeric: ", tNumericAtMin];
Print["Difference: ", tSymbolicAtMin [[2]] - tNumericAtMin // N];

:

⁃Graphics⁃
Differentiated integral is 2 t x + 98 t x^3 / 3 - 14 x^5 / 65
Exact: 21/3380
Numeric: 0.00621302
Difference: -3.01143 x 10^-9
0

A minimal function can only be at the zero points of its derivation, so why integrate first?

  • You can use FindRootor Solveto search for rootsg
  • Then you can verify that the points are truly local minima by checking the derivatives g(at this point it must be positive).
  • Then you can NIntegratefind the minimum value f- only one numerical integration!
-1
source

All Articles