Rejection sampling on uniform distribution?

Technical Source
1 min readJul 15, 2022

--

How can I use matlab to perform rejection sampling on a uniform distribution using rand, to pick 20% of samples in the range 0 to 0.2 and the other 80% between 0.2 and 1?

NOTE:-

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help , Finance Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

Try this:

numPoints = 1000  % Total number of points to save.
numLow = 1;
numHigh = 1;
% Start collecting elements using acceptance if in range,
% and rejection if out of range.
for k = 1 : 10000000 % enough to make sure we will collect at least numPoints elements.
r = rand();
% Save the number if it's in the low range.
if r <= 0.2 && numLow <= 0.20 * numPoints
% In range. Store/save the number.
lowKeepers(numLow) = r;
numLow = numLow + 1;
else
% Not in range so reject/ignore it.

SEE COMPLETE ANSWER CLICK THE LINK

--

--

Technical Source
Technical Source

Written by Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.