Exercise 3

We want to generate random numbers according to the law

f(x) = N × exp( - 3 × x )   for x ∈ [0,∞[ ,


with N being a normalization constant. The generation should be done using explicitely the fact that f(x) can be obtained from an elementary function using a scale change.

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