Find an estimate for $\int_{\pi/2}^\pi \sin(x) dx$ using the Monte Carlo Simulation

definite integralsintegrationmonte carlosimulationtransformation

I want to find an estimate for

$$\int_{\pi/2}^\pi \sin(x) dx$$

I want to use the monte carlo simulation method. I've plotted the graph of $\sin(x)$ in the given interval. The total area

$$\begin{align*}
A &= 1\cdot \frac{\pi}{2}\\[5pt]
&=\frac{\pi}{2}\\[5pt]
\end{align*}$$

The target area $a = \big(\frac{n}{N}\big) \cdot A$ where $n$ is the number of hits and $N$ is the total number of 'throws'. I've been given the following random numbers:

$$\begin {align}
8442 \quad 5653\\
2887 \quad 7703\\
6412 \quad 3965\\
4941 \quad 7376\\
0646 \quad 6931\\
7556 \quad 9697\\
\end {align}$$

What I need to do now is transform my $x$ values so they are in the range $\big(\frac{\pi}{2}, \pi\big)$, the graph only goes up to $y = 1$ so they $y$ values don't need to be transformed. Where I'm struggling is what transformation I should use on the random $x$-values, I tried $x_{transformed} = x_{random} +\big(\frac{\pi}{2}\big)$ but I didn't get any hits, my $\sin(x_{transformed})$ values were very low.

If anyone could help out and show me what transformation I should use on the $x$ values to get them in the range I require it would be much appreciated.

Thanks in advance

(I'll add the graph of $\sin(x)$ in the interval I require so you can see the rectangle and the target area:)
enter image description here

Best Answer

It looks like your $x_{random}$ values are from $0$ to $10000$. So dividing by $10000$, $x_{random}/10000$ is in the $[0,1]$ interval. Now multiply by the length of the desired interval, and shift it to the beginning of that interval: $$\frac{x_{random}}{10000}\frac{\pi}2$$ is in the $[0,\pi/2]$ interval $$\frac{x_{random}}{10000}\frac{\pi}2+\frac\pi2$$ is in the $[\pi/2,\pi]$ interval

Related Question