$A$ and $B$ are $n \times n$ matrices and $v$ is a vector with $n$ elements. $Av$ has $\approx 2n^2$ flops and $A+B$ has $n^2$ flops. Following this logic, $(A+B)v$ should be faster than $Av+Bv$.
Yet, when I run the following code in matlab
```A = rand(2000,2000);
B = rand(2000,2000);
v = rand(2000,1);
tic
D=zeros(size(A));
D = A;
for i =1:100
    D = A + B;
    (D)*v;
end
toc
tic
for i =1:100
    (A*v+B*v);
end
toc
```
The opposite is true. Av+Bv is over twice as fast. Any explanations?
First, let's clarify some terminology and assumptions. In your description, you stated that multiplying a matrix with a vector has approximately 2n^2 flops, which is inconsistent with the information you provided about A + B having n^2 flops. If we assume that both A and B are dense matrices and that the flop count for multiplying a matrix with a vector (Ax) is O(n^2), then Ax requires n^
It's important to note that in the code above, I am applying the matrices to the vector $v$ in each iteration, not just multiplying them once and then applying to $v$. This is a common mistake when comparing the computational costs of matrix-vector multiplication versus vector-sum-matrix multiplication.
To address your question, the reason why $(A + B)v$ is slower than $Av + Bv$ in your code is likely due to the