# Sum two Matrices

#1

I have a single (Nx7 Matrix) and a one dimensional Array of 7
i.e.
| A1, B1, C1, D1, E1, F1, G1 |
| A2, B2, C2, D2, E2, F2, G2 |
| A3, B3, C3, D3, E3, F3, G3 | (3x7)m

&

| A, B, C, D, E, F, G |

what would be the best way to query Scidb if the mathematical equation I want to perform is as follows:-

return value if
( [A1-A]^2 + [B1-B]^2 + [C1-C]^2 + [D1-D]^2 + [E1-E]^2 + [F1-F]^2 + [G1-G]^2 ) < .9

please note i want to perform this on each row of the matrix not just the first one.
I am aware I could simply write the statement as is, but in my program the number of columns is over 100 and the number of rows will be of an even greater number, so I was looking for a simpler way to write this query using aggregate or sum in scidb but I am unsure how to do that exactly, I have read the documentation on the AFL operators but it wasn’t of much assistance.

Thank you.

#2

Sure. You didn’t specify exactly what you want returned - just the sums that are below 0.9 or the rows of matrix for those sums. Here’s a starting point

``````\$ iquery -anq "store(build(<val:double>[i=1:3,3,0, j=1:7,7,0], double(random()%1000)/1000), m)"
Query was executed successfully

\$ iquery -anq "store(build(<val:double>[j=1:7,7,0], double(random()%1000)/1000), v)"
Query was executed successfully

\$ iquery -aq "filter(aggregate(apply(cross_join(m, v, m.j, v.j), d, pow(m.val-v.val, 2)), sum(d) as ds, i), ds<0.9)"
``````

To get all the rows of m for this result, simply cross-join that whole query back to m on i.

#3

that worked perfectly. Thank you.