I’m trying to learn how to correctly represent some code I have in vector notation. Apologies if it’s a bit convoluted, keep in mind I’m trying to learn how to better communicate it (!)
The code works on two inputs:
A vector of vectors of vectors - that we'll call A
A vector of vectors - called M
The base vector of each of these is a 2D position
The next level up is a vector of these positions – lets say there are 3 (x,y) positions in each. This defines ‘M’, and an example M might look like:
M = {(1,2) , (2,2) , (4,1)}
‘A’ however, has yet another level up, so for instance let’s say there are 4 vector of vectors (similar to the example M), in A - an example A:
A = [ {(1,1),(3,2),(4,1)} {(2,2),(2,5),(3,1)} {(4,2),(2,1),(4,7)} {(3,4),(5,2),(6,1)} ]
The operations I can only describe using my own system of notation, where a vector has three subscripts each numbering the element of the corresponding vector they came from.
For instance: M0x = 1, M0y = 2, M1y = 2, M2x = 4 …
And for A: A00x = 1, A10x = 2, A11y = 5, A32x = 6 …
(you’ll note I’ve used a 0 index origin – and have just labeled x and y exactly that)
In pseudo code the operation is as follows:
for (i = 0; i < 5; i++){
for (j = 0; j < 4; j++){ // <<edit: fixed small error here
Di += (Aijx - Mjx)^2 + (Aijy - Mjy)^2
}
}
I’m summing (+=) up the Euclidian distances each point in M is away from each point in each of the elements of A (not taking the square root however).
A random D might look like:
D = (13.344, 5.674, 4.2334, 12.556)
Question: How would this be written up in mathematical/vector notation?
As it’s in code, the col row thing is pretty arbitrary, so I’m open to ideas about how best to order that.
Without advice I'd just stick with my subscripts, and perhaps summations in place of the loops? But maybe there is some hidden vector stuff going on here or some other standard?
EDIT>> I guess in all fairness I'm interested to see what it might look like if I took square root before summing also ...