# Resolve integral with importance sample Monte Carlo

I'm trying to compute the integral $$\int_{a}^{b}(\sin( 1 + x ) + \cos( 1 + x ))e^{-x}\ dx$$

using importance sample Monte Carlo method. The exercise ask to use Cauchy Distribution to resolve the integral. Then $$\frac{1}{n}\sum_{i}^{n}\frac{f(x_i)}{g(x_{i})}$$ is an aproximation to the integral, where $g(x) = \frac{1}{\pi(1+x^2)}$(Cauchy distribution). To generate random numbers in a range $[a, b]$ following Cauchy distribution I used the inverse transformation: $$X = \tan(\arctan(a) + U(\arctan(b)-\arctan(a)))\quad \Rightarrow\quad \ U \sim(0,1)$$

but I did not get success.

$\newcommand{\+}{^{\dagger}} \newcommand{\angles}[1]{\left\langle\, #1 \,\right\rangle} \newcommand{\braces}[1]{\left\lbrace\, #1 \,\right\rbrace} \newcommand{\bracks}[1]{\left\lbrack\, #1 \,\right\rbrack} \newcommand{\ceil}[1]{\,\left\lceil\, #1 \,\right\rceil\,} \newcommand{\dd}{{\rm d}} \newcommand{\down}{\downarrow} \newcommand{\ds}[1]{\displaystyle{#1}} \newcommand{\expo}[1]{\,{\rm e}^{#1}\,} \newcommand{\fermi}{\,{\rm f}} \newcommand{\floor}[1]{\,\left\lfloor #1 \right\rfloor\,} \newcommand{\half}{{1 \over 2}} \newcommand{\ic}{{\rm i}} \newcommand{\iff}{\Longleftrightarrow} \newcommand{\imp}{\Longrightarrow} \newcommand{\isdiv}{\,\left.\right\vert\,} \newcommand{\ket}[1]{\left\vert #1\right\rangle} \newcommand{\ol}[1]{\overline{#1}} \newcommand{\pars}[1]{\left(\, #1 \,\right)} \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}} \newcommand{\pp}{{\cal P}} \newcommand{\root}[2][]{\,\sqrt[#1]{\vphantom{\large A}\,#2\,}\,} \newcommand{\sech}{\,{\rm sech}} \newcommand{\sgn}{\,{\rm sgn}} \newcommand{\totald}[3][]{\frac{{\rm d}^{#1} #2}{{\rm d} #3^{#1}}} \newcommand{\ul}[1]{\underline{#1}} \newcommand{\verts}[1]{\left\vert\, #1 \,\right\vert} \newcommand{\wt}[1]{\widetilde{#1}}$ The probability distribution which is normalized in $\ds{\left[a,b\right)}$ is given by: $${\rm P}\pars{x} = {1 \over \arctan\pars{b} - \arctan\pars{a}}\,{1 \over x^{2} + 1}$$
$$\int_{a}^{x}{\rm P}\pars{\xi}\,\dd\xi = \int_{0}^{U}\dd U'\quad\imp\quad {\arctan\pars{X} - \arctan\pars{a} \over \arctan\pars{b} - \arctan\pars{a}} =U$$ which leads to $\ds{\arctan\pars{X} =\arctan\pars{a} + \bracks{\arctan\pars{b} - \arctan\pars{a}}U}$: \begin{align} X = \tan\pars{\arctan\pars{a} + \bracks{\arctan\pars{b} - \arctan\pars{a}}} ={a + \tan\pars{\bracks{\arctan\pars{b} - \arctan\pars{a}}U} \over 1 - a\tan\pars{\bracks{\arctan\pars{b} - \arctan\pars{a}}U}}\tag{1} \end{align}
$$\sum_{i = 1}^{N}\fermi\pars{x_{i}} \approx N\int_{a}^{b}{\rm P}\pars{x}\fermi\pars{x}\,\dd x$$
$$\int_{a}^{b}{\fermi\pars{x} \over x^{2} + 1} \approx {\arctan\pars{b} - \arctan\pars{a} \over N}\sum_{i = 1}^{N}\fermi\pars{x_{i}}$$
\begin{align} &\color{#000}{\large% \int_{a}^{b}\bracks{\sin\pars{1 + x} + \cos\pars{1 + x}}\expo{-x}\,\dd x} \\[3mm]&\approx\color{#00f}{\large% {\arctan\pars{b} - \arctan\pars{a} \over N}\times} \\[3mm]&\color{#00f}{\large\sum_{i = 1}^{N} \bracks{\sin\pars{1 + x_{i}} + \cos\pars{1 + x_{i}}}\expo{-x_{i}} \pars{x_{i}^{2} + 1}} \end{align} with $\ds{\braces{x_{i}}}$ generated by $\pars{1}$ and associated $\ds{\braces{U_{i}}}$ generated by an uniform distribution in $\ds{\left[0,1\right)}$.
• thanks very much for the help. For example if I wanted to use the exponential distribution, it would be normalized in [a, b] is given by: $P(x) = \frac{e^{-x + a}}{e^{-b} - e^{-a}}$.Sorry about that more this question is that I'm comparing the distributions – user50098 May 11 '14 at 23:17