I am trying to find the maximum value $t$ such that my function $h$ is bigger than $t$ on (at least) half of the interval $[0,2\pi]$ and smaller than $t$ on the other half, i.e.: $$ \text{sup}\{t\in \mathbb{R} : \lambda(\{ x\in [0, 2\pi]: h(x)\geq t\})>\pi\}.$$
In my case, the function $h$ is the integral of the difference between two other functions, $f$ and $g$. I am trying to calculate the length of the interval where $h(x) \geq t$ by integrating a Boolean. I have tried the following:
Clear[f, g, h, q];
f[x_?NumericQ] = Sum[(1 - Abs[k]/6)*E^(I*k*(x - (Pi/3))), {k, -5, 5}];
g[x_?NumericQ] = Sum[(1 - Abs[k]/6)*E^(I*k*(x - (5*Pi/3))), {k, -5, 5}];
h[t_?NumericQ] = Integrate[f[x] - g[x], {x, 0, t}]/(2*Pi);
q[z_?NumericQ, v_?NumericQ] = Boole[Chop[h[v]] <= Chop[h[z]]];
FindMaxValue[{Chop[h[z]], (Integrate[q[z, v], {v, 0, 2*Pi}]) >= Pi}, z]
Now I am getting the following errors:
NIntegrate::inumr: The integrand q[1.,v] has evaluated to non-numerical values for all sampling points in the region with boundaries {{0,6.28319}}.
General::stop: Further output of NIntegrate::inumr will be suppressed during this calculation.
FindMaxValue::nrlnum: The function value {-[Pi]+!(*SubsuperscriptBox[([Integral]), (0), (2\ [Pi])](q[1.`, v] [DifferentialD]v))} is not a list of real numbers with dimensions {1} at {z} = {1.}.
I guess that the problem is that Mathematica is trying to evaluate q[1,v] which indeed is not a number. How do I get Mathematica to integrate this right?
q[1., 2.]
and didn't get a number. (Here2.
represents one of the sampling points and may not be one of the actual values forv
it used.) If you evaluateq[1., 2.]
you will get another clue about what is going wrong. $\endgroup$