Exercise 2

We want to generate random numbers according to the law

f(x) = N × x7   for x ∈ [0,1] ,


with N being a normalization constant.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.

We want to determine (as usual) 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 the corresponding 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