From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to generate random numbers with a known distributi​on f(X)=(8X^2 + 1)*Exp( -X^2 ).

Solved!
Go to solution

I need to simulate a random number generator which can generate numbers X with the probability distribution of 

 f (X) = ( 8X^2 + 1)*Exp ( -X^2 ).

 

This distribution is not a common distribution.

I have searched a lot, but I still do not know how to realize it.

 

 

Thanks a lot!

0 Kudos
Message 1 of 12
(3,380 Views)

The distribution (or histogram) is shown in this figure

distribution or historam.jpg

 

The random number what I expect is like this

random number I need.jpg

 

How  to  simulate this random number?

 

0 Kudos
Message 2 of 12
(3,374 Views)

The whole picturerandom number I expected.jpg

0 Kudos
Message 3 of 12
(3,366 Views)

Genererate a random number and insert it into your formula. 🙂

f (Random(X)) = ( 8X^2 + 1)*Exp ( -X^2 ).

 

The calculation and randomization can be found under Numeric menu.

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 4 of 12
(3,341 Views)

If you have a given distribution function, you can simulate matching random data by thesholding into the normalized integral of the function with a plain random number 0...1

 

See this example for more detail. (also look at the links)

 

 

In your case you need to decide on a useful range (e.g. -10...10), because your function goes to infinity on both sides. (Since you have negative values, you would also need to shift everything in the positive range (e.g. add 10) and then correct for the shift later.)

 

However, since your particular function is symmetric around 0, you can simply simulate the positive half (0..10), then switch sign with a probability of 0.5.  Should not be too hard.

 

See how far you get. Good luck! 🙂

Message 5 of 12
(3,335 Views)

To  Yamaeda,

 

Thanks a lot for your advice!

 

I tried but this simple program ran very slow.  And the result seemed not to be what I expected. 

p1.jpgp2.jpg

0 Kudos
Message 6 of 12
(3,305 Views)

To  ,

 

Thank you very much for your beautiful program!

 

I tried your method,  but not succeed.

My difficulty now is how to change distribution based on X axis to Y axis.

Would you please help me?

 

My results is  here

 

p3.jpg

p4.jpg

0 Kudos
Message 7 of 12
(3,300 Views)
Solution
Accepted by topic author laoda

Don't forget to index back into the original X array for correctly scaled data. Here's a simple example (LV 8.0):

 

 

 

Seems to work just fine. 😄

 

Download All
Message 8 of 12
(3,287 Views)

Dear ,

 

Thank you so much!

 My problem solved!

Download All
0 Kudos
Message 9 of 12
(3,255 Views)

Page.jpg

0 Kudos
Message 10 of 12
(3,248 Views)