-1

Possible Duplicate:
how to create normal distribution by using matlab

generate a random matrix consists of 100 rows and 100 columns that are normally distributed with mean 0 and standard deviation 25. I did the random matrix mat=rand(100,100) but then I dont know about normal distributed with mean 0 and standard deviation.

The next part is what is the probability of a given number in this matrix greeter than 25. As far as I understand, the number of probability should be the same everytime I run the script. Can I use randi?

Community
  • 1
  • 1
  • 3
    Hi and welcome to StackOverflow. In order to get a helpful answer here, you're urged to show some research effort first. Here are some pointers: 1. Learn about [normal distribution](http://en.wikipedia.org/wiki/Normal_distribution), 2. Read MATLAB's documentation about [`randn`](http://www.mathworks.com/help/matlab/ref/randn.html), 3. Define your question properly. What does "matrix greater than 25" mean? Do you mean an element in the matrix? You should also take look into [this question](http://stackoverflow.com/questions/4970679/how-to-create-normal-distribution-by-using-matlab)... – Eitan T Jan 15 '13 at 14:13
  • 1
    @Shai yes. I've already flagged it as a duplicate. – Eitan T Jan 15 '13 at 14:47
  • i dont think this one is similar to that question I know first part is similar but how about the probability part? – Sukitta Jia Jan 15 '13 at 18:12

1 Answers1

2

Your question has two parts. So is my answer:

  1. How to generate a matrix of size 100x100 where each entry is Normally distributed with mean = 0 and std = 25:

    You should use randn:

    mat = randn(100,100) * 25;
    
  2. What is the probability of an entry in mat to be greater than 25:

    You can sample from this probability using your generated mat by:

    prob = mean( mat(:) > 25 );
    

    However, prob is not the probability of the event "entry in mat is greater than 25". It is only a sample from that probability.

shoelzer
  • 10,648
  • 2
  • 28
  • 49
Shai
  • 111,146
  • 38
  • 238
  • 371
  • Can you explain why you multiply 25? I thought the standard deviation should be in the () – Sukitta Jia Jan 15 '13 at 14:23
  • the std is not an argument to `randn` that produces pseudo-random numbers with std = 1. In order to have different std, you simply multiply. Please see matlab's doc of `randn` - the link is in the question. – Shai Jan 15 '13 at 14:24
  • this is my code so far mat = randn(100,100)*25 numbercounter = 0 for i = 1:size(mat,1) for j = 1:size(mat,2) if mat(i,j) > 25 numbercounter = numbercounter + 1 end end end – Sukitta Jia Jan 15 '13 at 15:01
  • but I want to get the probability ... when I run the script the numbercounter keeps changing ... I thought it should be the same number no matter how many times I run this script – Sukitta Jia Jan 15 '13 at 15:03
  • The number of elements that are greater than 25 (`numberCounter`) is a **random variable** it is **NOT** a fixed number: for each random matrix `mat` `numCounter` indeed will have a different value. Please make sure you understand what you are asking... Are you sure you are entirely familiar with random variables, random matrices, etc.? – Shai Jan 15 '13 at 15:10
  • I dont understand at all and this is the first time I am using matlab .. the question is the question that I asked above .... my code now is mat = randn(100,100)*25 – Sukitta Jia Jan 15 '13 at 17:40
  • mat = randn(100,100)*25 this like is generating matrix 100*100 with random variables, am I correct? then I want to count so my next line is number counter = 10 then I use for loop – Sukitta Jia Jan 15 '13 at 17:43
  • for i = 1:size(mat,1) for j = 1:size(mat,2) if mat(i,j)>25 number counter = number counter + 1 end end end – Sukitta Jia Jan 15 '13 at 17:44
  • but the final answer that I need should be the probability not the numbercounter so the last line of my code is fprintf('%d/10000, P = %f\n', sum(randomnumbers>25), sum(randomnumbers>25)/10000) ... I have no clues the professor just said no matter how many times I run the script the probability should have the same value – Sukitta Jia Jan 15 '13 at 17:51
  • 1
    +1: I applaud your patience! – Eitan T Jan 15 '13 at 18:28