Create a vector z with 1000 elements generated by the rand-function. The generated values must have a mean value of 0.5 (mean(0.5)). And a standard deviation of sqrt(1/100*12), (std(x)).

4 visualizaciones (últimos 30 días)
So my task is to determine mean of an random vector to be set to 0.5. And the set standard deviation to be sqrt(1/100*12)
  2 comentarios
Adam
Adam el 7 de Sept. de 2018
And what have you done so far. I assume you have searched the Matlab help for functions such as 'rand' and followed the links from there to the other random number generation functions.
Rik
Rik el 28 de Jun. de 2023
What makes you think after almost 5 years that this question is unclear? Please provide an explanation in a comment.
I have removed your flag and will copy the question below.
Create a vector z with 1000 elements generated by the rand-function. The generated values must have a mean value of 0.5 (mean(0.5)). And a standard deviation of sqrt(1/100*12), (std(x)).
So my task is to determine mean of an random vector to be set to 0.5. And the set standard deviation to be sqrt(1/100*12)

Iniciar sesión para comentar.

Respuesta aceptada

Cesar Antonio Lopez Segura
Cesar Antonio Lopez Segura el 7 de Sept. de 2018
Hi all
Here the code:
mu = 0.5;
sigma = 0.3464;
z = mu + randn(1,1000)*sigma
STDcalculated = std( z )
MuCalculated = mean( z )
  3 comentarios
Vetle Normann
Vetle Normann el 7 de Sept. de 2018
Thank you! When I run loop on this script in Matlab STDcalculated and MuCalculated, the results are always close to 0.5 and 0.3463, but not the excact value. But is this as close as possible we get to 0.5 and 0.3464?
Cesar Antonio Lopez Segura
Cesar Antonio Lopez Segura el 7 de Sept. de 2018
Hi Vetle,
Using this values you can minimize your error:
mu = 0.50329141240781;
sigma = 0.347330944035507;

Iniciar sesión para comentar.

Más respuestas (1)

Torsten
Torsten el 7 de Sept. de 2018
Editada: Torsten el 7 de Sept. de 2018
0.5*(a+b) = 0.5
1/12*(b-a)^2 = 0.12
Solve for a and b.
This will give you the interval [a b] for which you must generate uniformly distributed random numbers.
Then you can use the rand-function as
z=a+(b-a)*rand(1000,1)
Best wishes
Torsten.

Categorías

Más información sobre Random Number Generation en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by