2
$\begingroup$

I'm trying to write a code which takes any $10\times10$ matrix as the input, assigns value of $i$ and $j$ to its elements based on their position in the matrix. Then using those values of $i$ and $j$ it creates a $100\times100$ matrix of 0 and 1 that the probability of 1, as a matrix element, is given by $Abs[((i - k) (j - l))]/500$ where $k$ and $l$ are the $i,j$ values of each of the other elements. This way the first line is using $i=1, j=1$ of the first matrix and so on to $i=10, j=10$. What I have done so far is:

Ev = Table[RandomChoice[{Abs[((((i - k)*(j - l)))/500)], 
    1 - Abs[((((i - k)*(j - l)))/500)]} -> {1, 0}], {i, 1, 10}, {j, 1, 
  10}, {l, 1, 10}, {k, 1, 10}]

But I don't know how to assign the initial values. Also this is wrong as it doesn't give the desired matrix. An example of 3x3 would be: I will explain it for a 3x3. Consider we have 3x3 matrix. a11 a12 a13 a21...a33. Then we have to assign values of i,j to each of these elements, such that for a11 i=1, j=1; for a23 i=2, j=3.... These will be our set of vertices for which were going to make an adjacency matrix. Now, we use those vertices to create an adjacency matrix of a graph as following: the probability that a11 is connected to a12 (there is 1 for the connection in the matrix) is Abs[((((i - k)(j - l)))/500)]= Abs[(1-1)(2-1)/500]. For a11 to a13 is Abs[(1-1)(1-1)/500] All the way to connection of a11 to a33 Abs[(1-3)(1-3)-500}. This would be the first line of the adjacency matrix graph(set of connections of a11). The same process is repeated for a22 connections to all vertices all the way to a33 to all vertices. Which gives us a 9*9 adjacency matrix of 0,1 for this example.

$\endgroup$
8
  • $\begingroup$ {(((i - k)*(j - l)))/500, 1 - ((((i - k)*(j - l)))/500)} will have negative values for some combination of i,j,k,l values`. $\endgroup$
    – kglr
    Dec 7 '20 at 4:32
  • 2
    $\begingroup$ I think the formulation of your question is not clear enough. $\endgroup$ Dec 7 '20 at 10:24
  • $\begingroup$ I agree with @DanielHuber. There appears to be a very real question lurking in here, but it is difficult to tease out exactly what is wanted. $\endgroup$ Dec 7 '20 at 15:03
  • $\begingroup$ Yes the values might have been negative, I made it right. $\endgroup$
    – Nishpish
    Dec 7 '20 at 16:11
  • 2
    $\begingroup$ Again, this could benefit from clarity. Perhaps give a very explicit example using a 3x3 to generate a 9x9. $\endgroup$ Dec 7 '20 at 18:07
1
$\begingroup$

Use ArrayFlatten to get a 100X100 matrix:

Ev2 = ArrayFlatten[Ev];

Dimensions[Ev2]
{100, 100}
ArrayPlot[Ev2]

enter image description here

If I understand "code which takes any 10×10 matrix as the input, assigns value of i and j to its elements based on their position in the matrix" correctly, you can get a matrix of indices in several ways:

SeedRandom[1]
n = 5;
somematrix = RandomInteger[10, {n, n}];

positionsmat1 = Array[List, {n, n}];
positionsmat2 = Table[{i, j}, {i, n}, {j, n}];
positionsmat3 = MapIndexed[#2 &, somematrix, {2}];

Row[Grid[#, Dividers -> All] & /@ 
 {somematrix, positionsmat1, positionsmat2, positionsmat3}, Spacer[10]]

enter image description here

$\endgroup$
1
  • $\begingroup$ Yes, this works perfectly for my first question. I updated it and have given more details for second part. $\endgroup$
    – Nishpish
    Dec 7 '20 at 22:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.