randn function with so many digits or huge numbers
Show older comments
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
Accepted Answer
More Answers (1)
Sean de Wolski
on 29 Apr 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 Comments
Sean de Wolski
on 29 Apr 2014
Oh and if you want to grow an array of identical values
zeros(10,1)
ones(10,1)
Metin
on 29 Apr 2014
Sean de Wolski
on 29 Apr 2014
round off error in the floating point calculations of standard deviation.
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!