Exercise 1
We want to generate random numbers according to the law
f(x) = exp(-x) for x ∈ [0,∞[ .
The generation should be done using the inversion method, based on our standard generator unif, as defined here, by employing "#include" to predefine unif, as explained here.
The random numbers have to be distributed according to the function f(x), which we are going to test, by determining the x-distribution, given (in the program) in terms of the two tables xmi[i] and phi[i], as explained here. The x-distribution should coincide with the function f(x), so we should find φi = f(xi) .
Write a program to generate Nsim = 10000 random numbers as explained above, and determine the x-distribution, i.e. determine xmi[i] and phi[i]. In addition also compute f(xi), using the table fun[i] in the program. Print xmi[i], phi[i], fun[i] to standard output. So when executing the program, we should get three columns, representing xmi[i], phi[i], fun[i].
For a possible graphical representation of the results, see here.
In case of problems in understanding basic notions of the programming langage C: see
C tutorial
The solution of this exercise can be found here