# Thread: Transform uniform numbers to numbers governed by probability density function

1. ## Transform uniform numbers to numbers governed by probability density function

Hi there MHF

I've got this problem which I'm stuck on. I'm generating random uniformly distributed numbers between 0 and 1, and I need to transform these numbers into numbers governed by the probability density function

Code:
f(y) = 0.2            for 0 < y ≤ 2
0.8y - 1.4     for 2 < y ≤ 3
0              elsewhere
Apologies for not knowing LaTex, here's a picture .

I believe the first thing I need to do is figure out the cumulative distribution function F(y), for this I came up with

Code:
f(y) = 0.2y                    for 0 < y ≤ 2
0.4y^2 - 1.4y + 1.6     for 2 < y ≤ 3
1                       3 < y
Next I think I need to find the transformation functions for 0 < y ≤ 2 and 2 < y ≤ 3. So by substituting the uniform variable U in I can get $y = U / 0.2$ for the first segment, however for the second segment (2 < y ≤ 3) I get two quadratics here (wolfram link) so I'm not sure if this is the right track or not.

Basically my understanding of how transforming these variables works goes like this

1) Generate uniform random variable U
2) If U is less than 0.4 (which I got from subbing y=2 into 0.2y), it is transformed using $y = U / 0.2$. Otherwise if U is greater than 0.4 it is transformed using one of the quadratics in the above link.

Anyone able to help me out here? Much appreciated

2. ## Re: Transform uniform numbers to numbers governed by probability density function

Edit: error removed

The CDF is:

Code:
F(y) = 0.2y  for 0 < y ≤ 2
0.4y^2 - 1.4y + 1.6 for 2 < y ≤ 3
1 for  3 < y
when you solve the quadratic and get two candidate functions for C(u), only one candidate will satisfy the initial conditions C(1)=3 and C(0.4)=2