0
$\begingroup$

For example, I have vector A = mx1. I want to sum each elements of vector A by :

1) Define vector B = 1xm.

2) Take : AxB = 1x1. So, this vector will be the value of sum elements of vector A.

But, I don't know how to choose vector B to this trick.

So, my question is : does exist vector B to do my trick, or if not, does exist a way just to do matrix manipulation (sum, multiplication, transpose...), and can do this trick, too. (it means : you not count each elements by hand)

Thanks :)

  • 3
    If you take $B$ to be all ones, and instead compute $BA$, then you get the sum of elements in $A$. By the dimensions of $A$ and $B$ above the matrix $AB$ will have dimensions $m \times m$. (I have posted this as an answer).2012-08-20

1 Answers 1

3

Let $A$ be a column-vector with $m$ elements, and let $B$ be a row-vector with $m$ elements, where each element of $B$ is 1. Then $BA = \begin{pmatrix} b_1 & b_2 & \ldots & b_m\\ \end{pmatrix} \begin{pmatrix} a_1 \\ a_2 \\ \vdots \\ a_m \end{pmatrix} = \sum_{i=1}^{m} b_ia_i = \sum_{i=1}^{m} 1 \cdot a_i = \sum_{i=1}^{m} a_i$ where $a_i$ is the $i$'th element of $A$.

The matrix $AB$ has dimension $m \times m$.

  • 1
    In short, take the dot product of the given vector with the vector whose entries are all $1$'s.2012-08-20