sum of rand matrix equal to zero
Mostrar comentarios más antiguos
Dear All,
I want to generate matrix A ,i.e. n by n random matrix but the sum(sum(A)) = zero. Help in this regard will be highly appreciated........
Regards..........
Respuesta aceptada
Más respuestas (2)
The command randn pulls from a normal distribution with distribution N(0,1), implying with a large enough sample the mean should be zero. The sum of all dimensions should also converge toward zero since the values above and below the mean will cancel each other out, as they have equal probability.
1 comentario
Offroad Jeep
el 17 de Mayo de 2016
Michael Haderlein
el 5 de Mayo de 2015
What kind of random distribution do you want? Here I use normal distribution, for other distributions just replace randn by the respective function:
n=100;
A=randn(100);
B=A-mean(A(:));
sum(B(:))
ans =
3.8913e-13
That's not exactly zero, but you'll not easily come close due to numerical precision.
1 comentario
Offroad Jeep
el 17 de Mayo de 2016
Categorías
Más información sobre Random Number Generation en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!