How to Create a 5x5 Random Matrix with Specific Range Using randn in MATLAB?

Click For Summary

Discussion Overview

The discussion revolves around generating a 5x5 random matrix in MATLAB using the randn function, specifically aiming to constrain the values within a range of -10 to 10. Participants explore the implications of using randn, which produces normally distributed values, and the challenges associated with setting appropriate parameters for mean and standard deviation.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant describes their initial approach using rand, which allows for direct control over the range, but notes the requirement to use randn instead.
  • Another participant explains that randn generates normally distributed random numbers with a mean of 0 and a standard deviation of 1, suggesting that the user needs to adjust these parameters to fit the desired range.
  • There is a discussion about the probability of values falling outside the specified range when using a normal distribution, particularly when considering standard deviations.
  • Two participants inquire about how to change the standard deviation from 1 to 3, indicating a need for clarification on the implementation of this adjustment.
  • One participant questions the appropriateness of setting the standard deviation to 3 and the reasoning behind choosing specific boundaries for the distribution.

Areas of Agreement / Disagreement

Participants express differing views on the best approach to using randn for this task, with no consensus on the optimal parameters for mean and standard deviation or the necessity of adjusting values that fall outside the desired range.

Contextual Notes

Participants have not resolved the implications of using a normal distribution for generating values within a specific range, nor have they agreed on the best method for handling out-of-bounds values.

Dell
Messages
555
Reaction score
0
i am using MATLAB 2008a, for the course i am doing i have been asked to make a random matrix A, 5x5 with a maximum possible value of 10 and a minimum of -10, so what i would have usually done is

Code:
A=-10+20*rand(5)

but i have been told to use the randn command, the problem is that the randn command doesn't have a maximum value of 1, and i cannot find its maximum possible value. what i have done is made the matrix and added a condition that
if A(i,j)>10, A(i,j)=10 and the same for -10, but there must be a better way.
 
Physics news on Phys.org
randn just gives you normally distributed random numbers. By default, I believe the distribution has a mean of 0 and a standard deviation of 1 ([itex]\sigma=1[/itex], working backwards from the example they provide on the documentation page):
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/randn.html

So, assuming you're familiar with the normal distribution (Gaussian) you just need to choose an appropriate mean value, and standard deviation such that you virtually never encounter values outside of your desired range (i.e. setting the boundaries such that they lie at a very low probability). Recall that even at 1 standard deviation ([itex]\sigma=1[/itex]), you have 68% of your distribution, and that at ([itex]\sigma=3[/itex]) you have 99.7% of your values:
http://en.wikipedia.org/wiki/Normal_distribution#Standard_deviation_and_confidence_intervals

However, you'll still need to go through and set values which lie beyond the limits to your limits (e.g. -10.5 to -10). Why? That's left as an exercise to the reader, but consider how many values you'd expect to lie outside your limits if you set your limits at the ([itex]\sigma=3[/itex]) value, and you had 1000 values.

Yes Virginia, cumulative knowledge is sometimes expected!
 
how can i change the stadnard deviation from 1 to 3?
 
Dell said:
how can i change the stadnard deviation from 1 to 3?

Look at the example in the documentation page for the randn function. And you still have to decide whether or not setting the standard deviation to 3 is acceptable! (As well, why 3 and 1/3 standard deviations to the boundaries?)
 

Similar threads

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