I have something like this
edgesList = {{1, 3}, {1, 5}, {2, 1}, {2, 6}, {5, 2}, {5, 6}, {6, 1}, {6, 4}}
And I need something like this as output.
{Subscript[x, 1 \[RightArrow] 3] + Subscript[x, 1 \[RightArrow] 5] -
Subscript[x, 2 \[RightArrow] 1] - Subscript[x, 6 \[RightArrow] 1],
Subscript[x, 2 \[RightArrow] 1] + Subscript[x, 2 \[RightArrow] 6] -
Subscript[x, 5 \[RightArrow] 2], -Subscript[x,
1 \[RightArrow] 3], -Subscript[x,
6 \[RightArrow] 4], -Subscript[x, 1 \[RightArrow] 5] + Subscript[x,
5 \[RightArrow] 2] + Subscript[x,
5 \[RightArrow] 6], -Subscript[x, 2 \[RightArrow] 6] - Subscript[x,
5 \[RightArrow] 6] + Subscript[x, 6 \[RightArrow] 1] + Subscript[x,
6 \[RightArrow] 4]}
I have accomplished this in procedural way, but I'm curious how to make it functional.
equations = Array[0 &, nVertexes];
For[i = 1, i <= nEdges, i++,
equations[[edgesList[[i, 1]]]] =
equations[[edgesList[[i, 1]]]] +
Subscript[x, edgesList[[i, 1]] \[RightArrow] edgesList[[i, 2]]];
equations[[edgesList[[i, 2]]]] =
equations[[edgesList[[i, 2]]]] -
Subscript[x, edgesList[[i, 1]] \[RightArrow] edgesList[[i, 2]]];];