I've been trying to approximate $\int_a^b f(x)\hspace{1pt} dx$ with the weight function $W(x)=A(e^{x^2}-1)$, $A$ is a constant of normalization (when $x\in[0,1]$ then $A=2.16145...$). I don't have any problems when the integration limits are $x \in [0,1]$, but the general case when $x \in [a,b]$ is cumbersome.
This is the procedure I followed for the $x \in [0,1]$ case:
- Choose a number $x_0$ in $[0,1]$
- Now set $x_t$ (trial step) to be $x_t=x_0 +$ Random[{-h,h}]
- Then set r to be: $r=\frac{W(x_t)}{W(x_0)}$ and compare it to some random number $\Omega_i \in \{0,1\}$
- If $r\geq\Omega_i$ then $x_t$ is accepted (i.e. $x_0=x_t$), but if $r<\Omega_i$ then $x_t$ is set to be $x_t= x_0$.
- Repeat discarding the $m$ first steps. (That is, to remove any dependence on the starting point, the algorithm is run for some large number of steps which are then discarded).
- Now calculate the integral $\int_a^b f(x)\hspace{1pt} dx$ as:
$\int_0^1 f(x)\hspace{1pt} dx=\int_0^1 \frac{f(x)}{W(x)}\hspace{1pt}W(x)dx\approx \frac{1}{(N-m)} \sum\limits_{i=1}^{N-m} \frac{f(x_i)}{W(x_i)}$.
I run the program for little $N$ to fixate h such as the acceptance ratio of $x_t$ is $\approx 50$% and then I re-run for a large $N$ with this $h$.
With $W(x)=A(e^{x^2}-1)$, $f(x)=x^2$, $N=1\times 10^6$, $m=1\times 10^5$ and $h=0.8$ (which gives an acceptance ratio of $50.8$%), I get $\int_0^1 x^2 dx=0.333305$, which is close enough to the actual value $\frac{1}{3}$;
What do I have to do in order for accounting the general integral limits? Do you have any suggestion? Do you suggest any book or paper I can read? Thank you in advance for your time.
P.S. English is not my first language.

Second, and for this one I am not sure why, but you must calculate $\int_a^b f(x)dx$ as $\int_a^b f(x)dx\approx \sum\limits_i \frac{f(\beta_i(b-a)+a)}{W(\beta_i(b-a)+a)}$ and not: $\int_a^b f(x)dx\approx(b-a)\sum\limits_i \frac{f(\beta_i(b-a)+a)}{W(\beta_i(b-a)+a)}$
– Leinad Aug 26 '20 at 14:57