Summation of 2D-array with constraints

120 Views Asked by At

Say I have the following 2D-array of money. (Imagine a id or number representation of types of money).

$money[TYPE][DAY]$

And I want to sum total amount of money for all types of money in day 0. How can this be represented using math?

Im a bit confused on how I can turn the "programming-logic" to a nicely formatted equation with the time constraint.

1

There are 1 best solutions below

0
On BEST ANSWER

Notice that the 2D array 'money' is a matrix. Usually we index matrices starting at 1, e.g. the first row is row 1. So $\text{money}[j][k]$ represents the amount of type '$j$' money on day '$k$'. So the sum of the $k$-th column is the sum of money on day $k$. I think if you write it as that or as the "$k$-th column sum" it will be clear. You can also write this as $$ \text{TotalMoney}(k)= \sum_{j=0}^n \text{money}(j,k) $$ if there are $n+1$ sources of money.

What's nice about the description as a matrix is you can use the 1-norm and $\infty$-norm of the matrix to calculate the largest column and row-sums respectively which would give the maximum amount of money received in a day and by a source respectively.