Asked by Offroad Jeep
on 5 May 2015

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..........

Answer by Hooman Habibi
on 5 May 2015

Accepted Answer

Subtract the mean from the samples:

n=10; z=randn(n,n); z=z-sum(sum(z))/(n*n); sum(sum(z))

Offroad Jeep
on 17 May 2016

Can you please check the attached problem.

Sign in to comment.

Answer by Bus141
on 5 May 2015

Edited by Bus141
on 5 May 2015

Offroad Jeep
on 17 May 2016

Can you please check the attached problem.

Sign in to comment.

Answer by Michael Haderlein
on 5 May 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.

Offroad Jeep
on 17 May 2016

Can you please check the attached problem.

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.