What is the difference between unifrnd and rand?

17 visualizzazioni (ultimi 30 giorni)
Natacha Comandante Lou il 12 Apr 2017
Risposto: Fei Deng il 17 Apr 2017
Since both unifrnd() and rand() generates random variables from a continuous uniform distribution, I wonder if there is any difference in terms of their usage and sampling accuracy etc., or the difference would just be the fact that unifrnd allows direct specification of the bounds of the uniform random variable.
Thanks!
0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Risposta accettata

Fei Deng il 17 Apr 2017
Hello Natacha,
the function unifrnd actually calls rand. If a and b are the two first arguments of unifrnd, and r is the output of unifrnd, what unifrnd does is:
a2 = a/2;
b2 = b/2;
mu = a2+b2;
sig = b2-a2;
r = mu + sig .* (2*rand(sizeOut,'like',mu)-1);
Of course there are some error checks as well.
Type the following command in the MATLAB command window to take a look of the code: >>edit unifrnd
Of course they are few other differences in terms of usage (syntax). You can find more information from help documentation. https://www.mathworks.com/help/stats/unifrnd.html?searchHighlight=unifrnd&s_tid=doc_srchtitle https://www.mathworks.com/help/matlab/ref/rand.html?searchHighlight=rand&s_tid=doc_srchtitle
Another difference is that unifrnd is accessible when you have installed Statistics and Machine Learning Toolbox.
0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Categorie

Scopri di più su Uniform Distribution (Continuous) in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by