MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

# Thread Subject: generate 50x1000 matrix given variance and mean

 Subject: generate 50x1000 matrix given variance and mean From: Jose Valerio Date: 24 Mar, 2009 23:39:01 Message: 1 of 11 Ok so I know how to generate a random matrix of 50x1000. What I need to do now is create it with mean 20 and variance 100. All I have is x = randn(50,1000); but the distribution has to have mean 20 and variance 100?? little hint here please?
 Subject: generate 50x1000 matrix given variance and mean From: andywocky@gmail.com Date: 24 Mar, 2009 23:44:34 Message: 2 of 11 On Mar 24, 7:39=A0pm, "Jose Valerio" wrote: > Ok so I know how to generate a random matrix of 50x1000. What I need to d= o now is create it with mean 20 and variance 100. > > All I have is x =3D randn(50,1000); > > but the distribution has to have mean 20 and variance 100?? little hint h= ere please? Hint:    z =3D randn(1000, 1) * sigma + mu; This creates a normal random vector with mean mu and variance sigma^2. Andy
 Subject: generate 50x1000 matrix given variance and mean From: Jose Valerio Date: 24 Mar, 2009 23:47:01 Message: 3 of 11 andywocky@gmail.com wrote in message ... > On Mar 24, 7:39=A0pm, "Jose Valerio" wrote: > > Ok so I know how to generate a random matrix of 50x1000. What I need to d= > o now is create it with mean 20 and variance 100. > > > > All I have is x =3D randn(50,1000); > > > > but the distribution has to have mean 20 and variance 100?? little hint h= > ere please? > > > Hint: > z =3D randn(1000, 1) * sigma + mu; > > This creates a normal random vector with mean mu and variance sigma^2. > > Andy I found this on matlab help: Generate a random distribution with a specific mean and variance . To do this, multiply the output of randn by the standard deviation , and then add the desired mean. For example, to generate a 5-by-5 array of random numbers with a mean of .6 that are distributed with a variance of 0.1, x = .6 + sqrt(0.1) * randn(5) So I did x = 20 + sqrt(100) * randn(50,1000)
 Subject: generate 50x1000 matrix given variance and mean From: John D'Errico Date: 25 Mar, 2009 00:06:03 Message: 4 of 11 "Jose Valerio" wrote in message ... > Ok so I know how to generate a random matrix of 50x1000. What I need to do now is create it with mean 20 and variance 100. > > All I have is x = randn(50,1000); > > but the distribution has to have mean 20 and variance 100?? little hint here please? Read this: doc randn HTH, John
 Subject: generate 50x1000 matrix given variance and mean From: Jose Valerio Date: 25 Mar, 2009 00:12:01 Message: 5 of 11 "John D'Errico" wrote in message ... > "Jose Valerio" wrote in message ... > > Ok so I know how to generate a random matrix of 50x1000. What I need to do now is create it with mean 20 and variance 100. > > > > All I have is x = randn(50,1000); > > > > but the distribution has to have mean 20 and variance 100?? little hint here please? > > Read this: > > doc randn > > HTH, > John I think the link didn't come up?? I'm not 100% sure if the way I did it is right
 Subject: generate 50x1000 matrix given variance and mean From: Jose Valerio Date: 25 Mar, 2009 00:21:11 Message: 6 of 11 "Jose Valerio" wrote in message ... > "John D'Errico" wrote in message ... > > "Jose Valerio" wrote in message ... > > > Ok so I know how to generate a random matrix of 50x1000. What I need to do now is create it with mean 20 and variance 100. > > > > > > All I have is x = randn(50,1000); > > > > > > but the distribution has to have mean 20 and variance 100?? little hint here please? > > > > Read this: > > > > doc randn > > > > HTH, > > John > > I think the link didn't come up?? > I'm not 100% sure if the way I did it is right I think I got it now. r = 20 + 100.*randn(50,1000);
 Subject: generate 50x1000 matrix given variance and mean From: John D'Errico Date: 25 Mar, 2009 00:33:01 Message: 7 of 11 "Jose Valerio" wrote in message ... > > I'm not 100% sure if the way I did it is right > > I think I got it now. > r = 20 + 100.*randn(50,1000); Very, very close. You asked for the VARIANCE to be 100. Multiply a unit normal random variable by a constant value k, and the standard deviation will be k. The variance (the square of the standard deviation) will be k^2. So you need to multiply by sqrt(100). John
 Subject: generate 50x1000 matrix given variance and mean From: Jose Valerio Date: 25 Mar, 2009 00:48:01 Message: 8 of 11 "John D'Errico" wrote in message ... > "Jose Valerio" wrote in message ... > > > > I'm not 100% sure if the way I did it is right > > > > I think I got it now. > > r = 20 + 100.*randn(50,1000); > > Very, very close. You asked for the VARIANCE to > be 100. > > Multiply a unit normal random variable by a constant > value k, and the standard deviation will be k. The > variance (the square of the standard deviation) will > be k^2. > > So you need to multiply by sqrt(100). > > John isn't that what I had on my second post? x = 20 + sqrt(100) * randn(50,1000)
 Subject: generate 50x1000 matrix given variance and mean From: John D'Errico Date: 25 Mar, 2009 00:55:06 Message: 9 of 11 "Jose Valerio" wrote in message ... > "John D'Errico" wrote in message ... > > "Jose Valerio" wrote in message ... > > > > > > I'm not 100% sure if the way I did it is right > > > > > > I think I got it now. > > > r = 20 + 100.*randn(50,1000); > > > > Very, very close. You asked for the VARIANCE to > > be 100. > > > > Multiply a unit normal random variable by a constant > > value k, and the standard deviation will be k. The > > variance (the square of the standard deviation) will > > be k^2. > > > > So you need to multiply by sqrt(100). > > > > John > > isn't that what I had on my second post? x = 20 + sqrt(100) * randn(50,1000) Yes. This is now correct. So then why did you change it incorrectly in your penultimate post? John
 Subject: generate 50x1000 matrix given variance and mean From: Jose Valerio Date: 25 Mar, 2009 01:07:01 Message: 10 of 11 "Jose Valerio" wrote in message ... > "John D'Errico" wrote in message ... > > "Jose Valerio" wrote in message ... > > > Ok so I know how to generate a random matrix of 50x1000. What I need to do now is create it with mean 20 and variance 100. > > > > > > All I have is x = randn(50,1000); > > > > > > but the distribution has to have mean 20 and variance 100?? little hint here please? > > > > Read this: > > > > doc randn > > > > HTH, > > John > > I think the link didn't come up?? > I'm not 100% sure if the way I did it is right I think I got it now. r = 20 + 100.*randn(50,1000);
 Subject: generate 50x1000 matrix given variance and mean From: Jose Valerio Date: 25 Mar, 2009 01:11:02 Message: 11 of 11 "John D'Errico" wrote in message ... > "Jose Valerio" wrote in message ... > > "John D'Errico" wrote in message ... > > > "Jose Valerio" wrote in message ... > > > > > > > > I'm not 100% sure if the way I did it is right > > > > > > > > I think I got it now. > > > > r = 20 + 100.*randn(50,1000); > > > > > > Very, very close. You asked for the VARIANCE to > > > be 100. > > > > > > Multiply a unit normal random variable by a constant > > > value k, and the standard deviation will be k. The > > > variance (the square of the standard deviation) will > > > be k^2. > > > > > > So you need to multiply by sqrt(100). > > > > > > John > > > > isn't that what I had on my second post? x = 20 + sqrt(100) * randn(50,1000) > > Yes. This is now correct. So then why did you > change it incorrectly in your penultimate post? > > John Because I was doing it from this: Generate values from a normal distribution with mean 1 and standard deviation 2. r = 1 + 2.*randn(100,1); and I miss-read it, it's doing it for std 2 not VARIANCE, that's where I made the mistake. Thanks for your help