I'm taking a class where we're working with matrix applications inside of Mathematica. In this case, we're analyzing senatorial votes that have been numericized so that a value of 1 corresponds to "aye," -1 corresponds to "nay," and 0 corresponds to no vote/abstain.
Taking the dot products of these values, I'm trying to find, for each senator, the senator(s) with the most and least similar voting patterns (largest and smallest dot products) and plot these in a chart.
This may not be the most efficient code to accomplish this, but given that it's for a class, I am supposed to modify what's below:
closestvoter[n_] :=
Module[{max = 0, k = 0, close = 0},
For[i = 1, i < 100, i++,
k = senatorvote[n] . senatorvote[i];
If[k >= max && i != n, close = i; max = k];
];
close
]
The way the code works right now, it will only give me a single value of i when sometimes there is more than one senator that produces the same dot product. How can I get the loop to check and print all values of i that satisfy this?