You have posed a interesting problem, with a subtle flaw that possibly you don't understand.
You asked to find an integral limit such that integral(sin(x)) == 2.
Ok. first, analytically, this might seem pretty easy.
I'll pick some arbitrary lower limit, not random, since I want it to be repeatable.
upsol = solve(int(F,[lolim,uplim]) == 2,returnconditions = true)
upsol =
uplim: [2x1 sym]
parameters: k
conditions: [2x1 sym]
disp(char(upsol.uplim))
[acos(cos(1/2) - 2) + 2*k*pi; 2*k*pi - acos(cos(1/2) - 2)]
So there are infinitely many solutions. A fundamental one happens when k == 0.
disp(char(subs(upsol.uplim,'k',0)))
[acos(cos(1/2) - 2); -acos(cos(1/2) - 2)]
double(subs(upsol.uplim,'k',0))
ans =
3.1416 - 0.4899i
-3.1416 + 0.4899i
Do you see? The solution is complex. Effectively, there are no solutions to the problem in real numbers.
If you set the lower limit to 0, then things get better.
The problem is, if you set the lower limit to something other than some integer multiple of 2*pi, then you can't achieve an integral of 2.
And of course, it gets worse yet, if you use trapz. The problem is, no matter how small you st the increment, trapz will ALWAYS under-estimate the integral of a purely convex function like sin(x). For example...
What happens ism no matter how small the stepsize, trapz will underestimate the integral, BECAUSE it puts trapezoidal polygon under the curve. And for a convex function like sin(x), on an integrl where in theory the integral wants to be 2 exactly, trapz always misses by just a tiny bit, UNDER the true value.
So nothing you can do will allow trapz to solve the problem. You can never get all of the way there.
Now, suppose the goal was to find a point using numerical methids, such that the integral is 1, as close as trapz can do? That is doable.