Difference rand and randn command matlab

  • Thread starter Thread starter eltrinco
  • Start date Start date
  • Tags Tags
    Difference Matlab
Click For Summary
SUMMARY

The discussion clarifies the differences between the MATLAB commands rand and randn. The rand function generates a matrix of pseudo-random numbers uniformly distributed between 0 and 1, while randn produces a matrix of pseudo-random numbers that follow a normal distribution with a mean of zero and a variance of one. Both functions accept similar arguments, allowing for flexible matrix dimensions. Users are encouraged to visualize the output by plotting the generated vectors.

PREREQUISITES
  • Understanding of MATLAB syntax and functions
  • Familiarity with random number generation concepts
  • Basic knowledge of statistical distributions, specifically uniform and normal distributions
  • Experience with data visualization techniques in MATLAB
NEXT STEPS
  • Explore the MATLAB documentation for rand and randn in detail
  • Learn about the implications of using uniform versus normal distributions in simulations
  • Investigate advanced random number generation techniques in MATLAB
  • Practice plotting random data using MATLAB's plotting functions
USEFUL FOR

Mathematics students, data scientists, and engineers who utilize MATLAB for simulations and statistical analysis will benefit from this discussion.

eltrinco
Messages
6
Reaction score
0
i am confused between when to use rand and randn . can someone explain to me please?
 
Physics news on Phys.org
Both are pseudo-random number generators.
http://www.mathworks.com/help/matlab/random-number-generation.html

type "help rand" and "help randn" for a description.

Code:
rand()
Return a matrix with random elements uniformly distributed 
on the interval (0, 1).  The arguments are handled the same 
as the arguments for `eye'.

randn() 
Return a matrix with normally distributed pseudo-random 
elements having zero mean and variance one.  The arguments 
are handled the same as the arguments for `rand'.

You should be able to see the result by filling a vector with them and plotting.
 
  • Like
Likes   Reactions: 1 person

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
Replies
3
Views
29K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 10 ·
Replies
10
Views
2K
Replies
8
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
15
Views
3K
Replies
3
Views
2K