So I am trying to think of a way to make a Matrix-Vector multiplication. What I have is a global stiffness matrix of 1D element with linear shape functions
$\begin{bmatrix} \dfrac{1}{3} & \dfrac{1}{6} & 0 & 0 \\ \dfrac{1}{6} & \dfrac{2}{3} & \dfrac{1}{6} & 0 \\ 0 & \dfrac{1}{6} & \dfrac{2}{3} & \dfrac{1}{6} \\ 0 & 0 & \dfrac{1}{6} & \dfrac{1}{3} \\ \end{bmatrix}$
What I mean is, say I have a vector $\begin{bmatrix} x_1 & x_2 & x_3 & x_4 \end{bmatrix}^{T}$. And I don't want to create extra memory in my computational implementation. Hence I want to recycle the memory that has been allocated to the original vector again.
My instinct is that there should be a way out for this, like how computer scientist (which I am not!) has shows how to swap x and y without using an extra variable by:
a = a + b;
b = a - b;
a = a - b;
Anyone has any thoughts?
What about just writing a function that multiplies a vector by this matrix using a for loop? You can overwrite $x$ as the multiplication is performed, something like this:
After the loop, the variable $x$ will store the result of the matrix-vector product.
You could also note that you are performing a convolution, which can be computed very efficiently using the Fast Fourier Transform (if you are careful to handle the boundary correctly). But since your convolution kernel is so small, this might not be faster than just using a for loop. And the FFT approach might not conserve memory as much as you want. Although, I just googled and learned that "in place" FFT algorithms have been developed which aim to conserve memory.