NIntegrate does not seem to like Intervals as regions. Consider the following example function defined for a parameter "a":
f[a_, t_?NumericQ] := t^3; Let us integrate the function over an interval:
a = 3; NIntegrate[f[a, t], t ∈ Interval[{2, 4}]] Guess what... The classical error "The integrand f[a,{NIntegrate`XR[1]}] has evaluated to non-numerical values for all sampling points in the region with boundaries {{2,4}}". Now, let us re-write the integral:
NIntegrate[f[a, t], {t, 2, 4}] and suddenly there are no problems with the integrand, and the integral correctly evaluates to 60. Interval is also a geometric region:
RegionQ[Interval[{2, 4}]] True Does anyone understand what the problem is?
Update
I was asked by rhermans to provide more background on the problem: I want to use NMinimize to set parameters defining the integration region in order to find a region minimising an integral. The region can potentially consist of several regions. The nice thing about the Interval function is that it merges overlapping intervals into longer intervals.
An obvious workaround in my case is to split the integral into several integrals, one for each continuous interval using the range form of NIntegrate that works, and then add them together:
Apply[Plus, Map[ NIntegrate[ f[a, t], Prepend[#, t] ] &, Apply[List, ComputedInterval[AssignedParameters] ] ]]; The computed interval is based on the parameters set by NMinimize, and since a discontinuous interval is just a list of sub-intervals, the last Apply simply turns the interval into a list of continuous ranges that can be passed to NIntegrate. Not very elegant, but it bypasses the issue.
