Exercise 5

We want to generate random numbers according to the discrete law

f(xi) = N × ( 1 / xi )   for xi ∈ {1,2,3} ,


with N being a normalization constant.

We want to determine 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(xi), 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