1. ## Classical Monte Carlo

I am interested to find out:

$\displaystyle \int ((\frac{2(cos(\pi x/2)}{3(1-x^2)}-\frac{2}{\pi})^2. 3(1-x^2)/2.dx$

I want use $\displaystyle \frac{1}{m}\displaystyle\sum_{i=1}^{m}(\frac{2(cos (\pi x^{(i)}/2)}{3(1-x^{(i)}^2)})^2$ where $\displaystyle x^{(i)}$ is drawn from $\displaystyle 3(1-x^2)/2$ (a density defined from 0<x<1).

The question is simple. How can I draw a random sample of let say 10000 from the density $\displaystyle f(x)= 3(1-x^2)/2$ ?

What I did is to generate 10000 random uniform variable and subst into the equation.
For example:

x=runif(10000)
g=3(1-x^2)/2

but the answer is still wrong after computation
Meanwhile finding this inverse is hard

2. Originally Posted by noob mathematician
I am interested to find out:

$\displaystyle \int ((\frac{2(cos(\pi x/2)}{3(1-x^2)}-\frac{2}{\pi})^2. 3(1-x^2)/2.dx$

I want use $\displaystyle \frac{1}{m}\displaystyle\sum_{i=1}^{m}(\frac{2(cos (\pi x^{(i)}/2)}{3(1-x^{(i)}^2)})^2$ where $\displaystyle x^{(i)}$ is drawn from $\displaystyle 3(1-x^2)/2$ (a density defined from 0<x<1).

The question is simple. How can I draw a random sample of let say 10000 from the density $\displaystyle f(x)= 3(1-x^2)/2$ ?

What I did is to generate 10000 random uniform variable and subst into the equation.
For example:

x=runif(10000)
g=3(1-x^2)/2

but the answer is still wrong after computation
Meanwhile finding this inverse is hard
Make sure you know what the support of the f(x) is first, and check that it is a pdf, then look at:

Inverse transform sampling!

It might be easier to use rejection sampling though for this pdf

CB

3. Originally Posted by noob mathematician
I am interested to find out:

$\displaystyle \int ((\frac{2(cos(\pi x/2)}{3(1-x^2)}-\frac{2}{\pi})^2. 3(1-x^2)/2.dx$

I want use $\displaystyle \frac{1}{m}\displaystyle\sum_{i=1}^{m}(\frac{2(cos (\pi x^{(i)}/2)}{3(1-x^{(i)}^2)})^2$ where $\displaystyle x^{(i)}$ is drawn from $\displaystyle 3(1-x^2)/2$ (a density defined from 0<x<1).

The question is simple. How can I draw a random sample of let say 10000 from the density $\displaystyle f(x)= 3(1-x^2)/2$ ?

What I did is to generate 10000 random uniform variable and subst into the equation.
For example:

x=runif(10000)
g=3(1-x^2)/2

but the answer is still wrong after computation
Meanwhile finding this inverse is hard
Would it not be simpler to use:

$\displaystyle \frac{1}{m}\displaystyle\sum_{i=1}^{m}\left\{ \left(\frac{2(cos(\pi x^{(i)}/2)}{3(1-(x^{(i)})^2)}-\frac{2}{\pi}\right)^2 \times \left[3(1-(x^{(i)})^2\right)/2]\right\}$

with $\displaystyle $$x^{(i)} sampled from \displaystyle U(0,1) ? CB 4. Originally Posted by CaptainBlack Would it not be simpler to use: \displaystyle \frac{1}{m}\displaystyle\sum_{i=1}^{m}\left\{ \left(\frac{2(cos(\pi x^{(i)}/2)}{3(1-(x^{(i)})^2)}-\frac{2}{\pi}\right)^2 \times \left[3(1-(x^{(i)})^2\right)/2]\right\} with \displaystyle$$ x^{(i)}$ sampled from $\displaystyle U(0,1)$ ?

CB
Amazing! I should have thought of that. Thanks again