What I want to do
I want to create a program that generates a random matrix nxn (2D array) on which I have to make calculations whose elements are symmetric to its main diagonal and the sum of each row equals to 1.
Details
I have tried too many algorithms but no one is working properly, I can do the matrix symmetric by typing
for i=1:n
n=rand(100);
for j=1:n
if(j>i)
matrix(i,j) = rand(100);
matrix(j,i)=matrix(i,j);
else if (j==i)
matrix = rand(100);
end
end
end
I can do also the sum of the row of the matrix equal to 1 by finding the sum on each row and then dividing each element with the sum of that row, and then when I make the sum of the row it equals 1
for i=1:n
for j=1:n
matrixS(i,j) = matrix(i,j)/sum(i); % The vektor of the row sums is made by another algorithm
end
end
Issue
The problem is when I want to make this array with all the characteristics I mentioned, each row equals 1 and the matrix is symmetric by the main diagonal
Any ideas?