randn function with so many digits or huge numbers
Afficher commentaires plus anciens
Hallo my question is about generating normal distributed random numbers with randn function of MATLAB, e.g.
x=25.589665545.*(1+0*randn(100,1));
std(x)
ans =
1.7853e-014
or with huge numbers :
y=10^25.*(1+0*randn(10000,1));
std(y)
ans =1.0631e+012
is that not strange? to be sure there are some other ways to generate array with constant numbers, but I see this when I want to generate variables with different deviations, for any command pthanks in advance
Réponse acceptée
Plus de réponses (1)
Sean de Wolski
le 29 Avr 2014
Not strange at all!
(1+0*randn(10,1))
Note the zero times randn - all of those components are zero. The very small standard deviation is pretty close to the eps(x) so it's just roundoff error in the calculation of x.
4 commentaires
Sean de Wolski
le 29 Avr 2014
Oh and if you want to grow an array of identical values
zeros(10,1)
ones(10,1)
Metin
le 29 Avr 2014
Sean de Wolski
le 29 Avr 2014
round off error in the floating point calculations of standard deviation.
Catégories
En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!