I have a matrix called $ A $ with elements equal to $ 0 $ and $ 1 $. if element $ A _ { i j } $ is equal to $ 1 $, it means that member $ i $ is connected to member $ j $ directly. if elements $ A _ { j k } $ is equal to $ 1 $, and $ A _ { k i } = 0 $, it means that member $ k $ and $ i $ are not directly linked but the are linked indirectly. I want to create a matrix called $ B $ which its elements are $ 0 $ or $ 1 $. If element $ B _ { m n } $ is equal to $ 1 $, it means that member $ m $ and $ n $ are linked (directly or indirectly). Could anyone give an answer how can I create $ B $ matrix from matrix $ A $?
$\endgroup$1 Answer
$\begingroup$Your matrix $A$ is known as the adjacency matrix in graph theory.
To get your matrix $B$ you have to look at the powers of $A$: The entry $(i,j)$ of $A^n$ is positive if and only if there is a path of length $n$ connecting vertex $i$ and vertex $j$. This allows you to define $B$ as follows: $$B_{ij} = \begin{cases} 1, & \exists n \in \mathbb{N}: (A^n)_{ij} \neq 0,\\ 0, &\text{otherwise.} \end{cases}$$ Note that it should be sufficient to only look at powers of $A$ up to the number of vertices.
$\endgroup$ 2