# What is the complexity of multiplication a real matrix with real vector

I have a real matrix $$Z$$ which is following the form as following:

$$Z = \begin{bmatrix} x_1& 0& 0& 0& 0& 0& 0& 0\\ 0& x_2& 0& 0& 0 & 0& 0& -x_4\\ 0& 0& x_3& 0& 0& 0& -x_3& 0\\ 0& 0& 0& x_4& 0& -x_2& 0&0 \\ 0& 0& 0& 0& -x_1& 0& 0& 0\\ 0& 0& 0& -x_2& 0& -x_4& 0& 0\\ 0& 0& -x_3& 0& 0& 0 & -x_3& 0\\ 0& -x_4& 0& 0& 0& 0& 0& -x_2 \end{bmatrix}$$

If the above matrix is multiplied with a real vector $$x$$, what will be the complexity in function of real multiplications and real addition?

• I believe your question fits better in the Computational Science StackExchange (scicomp.stackexchange.com) or the Computer Science StackExchange (cs.stackexchange.com) [I believe the fist is a better match though]. Jul 3, 2022 at 10:02
• What keeps you from counting the number of multiplications and additions yourself? Jul 3, 2022 at 10:56
• @MattL. I mean will the similarity of elements reduce the required real operations? That is what I am looking for. For example $x_2$ has been repeated for four times. On the other hand, yes I agree with you that counting the number of multiplications and additions can be done straightforwardly.
– Gze
Jul 3, 2022 at 11:04

If you multiply an $$M \times N$$ matrix with an $$N \times 1$$ vector you get a vector of size $$M \times 1$$

For the generic case you will need $$M \cdot N$$ multiplications and $$M \cdot (N-1)$$ additions.

For a sparse matrix the number of multiplications can be reduced to the number of non-zero elements and the number of additions is somewhat less, depending on the exact strucure of the sparsity. In your case that would be 14 multiplications and 6 additions.

I mean will the similarity of elements reduce the required real operations?

Not, if this is single multiply and you don't apply any constraints on the vector data. You can theoretically eliminate multiplications if you have identical elements in a column, but that's not the case here.

There could be reduction of complexity if you need to apply the same matrix multiplication repeatedly on a stream of data, but that depends on the details.

• you mean $(N-2)$ addition, but what's about the 16? I think it should be 14 which is $(2(N-1))$ as two columns have only one non-zeros value. Am I correct ?
– Gze
Jul 3, 2022 at 13:45
• Yep, 14, not 16, fixed. And I do mean $M \times (N-1)$ for the generic case, if that's what you mean. For the spares case it's the sum over all rows of "non-zero-elements -1", not $N-2$. In your case this is just coincidence. Jul 3, 2022 at 14:40
• what about if we multiplied $[Z , -Z]$ with a real vector with length $2N$? will the complexity be doubled also ?
– Gze
Jul 4, 2022 at 3:08
• What exactly does does $[Z,-Z]$ mean ? Jul 4, 2022 at 16:26
• $[Z, -Z]$ is just a matrix which collect the matrix $Z$ with its negative version. for example if it's of size $2 \times 2$, the new matrix will be $2 \times 4$.
– Gze
Jul 5, 2022 at 2:12